Package 'textrar'

Title: Interface to 'TexTra' from R
Description: A wrapper for the 'TexTra' API <https://mt-auto-minhon-mlt.ucri.jgn-x.jp/>, a web service for translating texts between different languages. 'TexTra' API account is required to use the service.
Authors: Toshikazu Matsumura [aut, cre]
Maintainer: Toshikazu Matsumura <[email protected]>
License: MIT + file LICENSE
Version: 0.8.0
Built: 2025-01-22 03:55:49 UTC
Source: https://github.com/matutosi/textrar

Help Index


Return the base URL for the API

Description

Return the base URL for the API

Usage

base_url()

Value

A string containing the base URL.

Examples

base_url()

Extract Translated Text from Response

Description

This function extracts the translated text from the response. returned by the post_request() function.

Usage

extract_result(res)

Arguments

res

The response object returned by the post_request().

Value

A character string containing the translated text.

Examples

## Not run: 
res <- post_request(paramas, "Hello world!")
translated <- extract_result(res)

## End(Not run)

Generate parameters for API call

Description

This function generates a list of parameters that can be used to make an API call.

Usage

gen_params(key, secret, name, api_name = "mt")

Arguments

key

The API key.

secret

The API secret.

name

The name of the API.

api_name

The name of the API to use. Defaults to "mt".

Value

A list of parameters.

Examples

## Not run: 
key <- "abcdefghijklmnopqrstuvw01234567890abcdef1" # API key
secret <- "xyzabcdefghijklmnopqrstuvw012345"       # API secret
name <- "login_ID"                                 # login_ID
params <- gen_params(key = key, secret = secret, name = name)

## End(Not run)

Get Access Token

Description

This function retrieves an access token from the API using the provided key and secret.

Usage

get_token(key, secret)

Arguments

key

The API key.

secret

The API secret.

Value

A character string containing the access token.

Examples

## Not run: 
key <- "abcdefghijklmnopqrstuvw01234567890abcdef1" # API key
secret <- "xyzabcdefghijklmnopqrstuvw012345"       # API secret
token <- get_token(key = key, secret = secret)

## End(Not run)

Send a POST request to the API

Description

This function sends a POST request to the API with the specified parameters and text.

Usage

post_request(params, text)

Arguments

params

A list of parameters to be passed to the API.

text

The text to be translated.

Value

The response from the API.

Examples

## Not run: 
post_request(params = , text = "Hello, world!")

## End(Not run)

Translate text using Transliteration Model

Description

This function translates text using a transliteration model.

Usage

textra(text, params, model = "transLM", from = "en", to = "ja")

Arguments

text

The text to be translated.

params

A list of parameters to be passed to the API.

model

The model to be used for translation.

from

The source language.

to

The target language.

Value

The translated text.

Examples

## Not run: 
text <- "Hello world"
key <- "abcdefghijklmnopqrstuvw01234567890abcdef1" # API key
secret <- "xyzabcdefghijklmnopqrstuvw012345"       # API secret
name <- "login_ID"                                 # login_ID
params <- gen_params(key = key, secret = secret, name = name)
translated <- 
  textra(text, params, model = "transLM", from = "en", to = "ja")
translated

## End(Not run)