Translation Service Introduction —— V3

1. Overview of services

LiveData Open Translation Platform aims at providing open services for a wide range of developers in the game industry.

2. Apply for services

Translation API uses a complete flow and self-application model. Click on “Login” at the top of LiveData’s official website (https://www.ilivedata.com), and sign up following the instructions. Choose AI Live Translation Service and create an application. A pid and a service key will be sent to you.

You can also activate other services on the Management Console - Overview Page.

3. Access Method

Header Value Description
Content-Type application/json
Accept application/json
X-AppId Application ID or Project ID
X-TimeStamp Request time in UTC format For example: 2010-01-31T23:59:59Z.  (for more information, go to http://www.w3.org/TR/xmlschema-2/#dateTime).
Authorization Signature Token Check Authentication section below
  • Request parameter
Parameter Required/Optional Description
q Required Please input source text. This text should be a UTF-8 encoded string with no more than 1024 characters.
source Optional Language of the source text. Set to one of the ISO 639-1 language codes listed in Language Support. If the source language is not specified or the source value is empty or invalid, the API will attempt to detect the source language automatically and return it within the response.
target Required Set target language for translation as one of the ISO 639-1 language codes listed in Language Support.
suggestedSource Optional Fallback reference language. When automatic language detection fails, this language can be used as the source language. Set to one of the ISO 639-1 language codes listed in Language Support.
profanity Optional Sensitive word filtering. Set as one of the following two options: off or censor. If this parameter is not set, it will be set as off by default. (1) off: don’t filter sensitive words. (2) censor: If there are sensitive words in translated texts, they will be replaced by asterisks (*) in translation results.
fromId Optional The sender’s ID of the text to be translated. When using the context translation model, this parameter needs to be passed.
toId Optional The recipient’s ID of the text to be translated.
precedingContext Optional This parameter is the contextual information for the text that needs to be translated, provided as a list of JSON objects. It is required when using a context-aware translation model. Each object contains two fields: userId (the user ID) and text (the preceding text in any language). The data should be input as follows: “precedingContext”: [{“userId”: “user1”, “text”: “123”}, {“userId”: “user2”, “text”: “456”}].
  • Request signature:

When the user requests the Image Check API, the request can be signed with the appId and secretKey (obtained from the Console - Service Configuration). When the API receives the request with the signature information, it will verify the signature using the same algorithm, and if the signature is found to be inconsistent, the API will return 401 error to the user.

If the API validation signature is consistent and the user corresponding to the appId has permission to operate the requested resource, the request succeeds, otherwise the API returns 401 error.

  • Request Header to send a signature via HTTP

Method: Add a header named Authorization in the request, whose value is the signature value. For example:

 Authorization: ****
  • Signature calculation method
  1. Canonicalized Query String:

Convert the request body JSON string to a hexadecimal string (not Base64) by doing sha256 encoding with UTF-8 character encoding.

CanonicalizedQueryString = hex(sha256(jsonBody))

  1. Constructs the signed string StringToSign ("\n" stands for ASCII newline character):

    StringToSign = HTTPMethod + “\n” + HostHeaderInLowercase + “\n” + HTTPRequestURI + “\n” + CanonicalizedQueryString < Get from previous step> + “\n” + “X-AppId:” + SAME_APPID_IN_HEADER + “\n” + “X-TimeStamp:” + SAME_TIMESTAMP_IN_HEADER

The HTTPRequestURI is the absolute path to the request URI, without the request string. If the HTTPRequestURI is empty, also keep a forward slash (/).

The hash-based message authentication code (HMAC) is created using the HMAC-SHA256 protocol and the signature is calculated.

For more information about HMAC, see: https://tools.ietf.org/html/rfc2104

  1. StringToSign as the signature string, secretKey as the secret key and SHA256 as the hash algorithm.

  2. Converting the results of the previous step to a BASE64 string.

  3. Put the BASE64 string into the Authorization of HTTP request Header.

  • Example of signature
  1. Below is an example of appId & secretKey.

    appId=999
    secrectKey=HSA3R+UQYYasWX1ZLrxzDTZxjrMW1ghD6DBbC4gnIjs=
    
  2. Below is an example request.

Request Json:

{"q": "hello world", "target": "zh-CN", "fromId": "user1", "precedingContext": [{"userId": "user1", "text": "123"}, {"userId": "user2", "text": "456"}]}

Generate CanonicalizedQueryString: b79fac47c8936c61bb90fa4f70babb4d62feb196cf741d22ce02751a5bb47d53

  1. Generate StringToSign

    POST\n
    translate.ilivedata.com\n
    /api/v3/translate\n
    b79fac47c8936c61bb90fa4f70babb4d62feb196cf741d22ce02751a5bb47d53\n
    X-AppId:999\n
    X-TimeStamp:2024-09-06T11:46:26Z
    
  2. Signatures from HMAC calculation

    f1O6j0cXEKkhKQji43p+/uMQSDAX9ht2LrbTLQ08kSQ=
    
  • HTTP response:

Content-Type: application/json;charset=UTF-8

The result is in JSON format, parameter description:

Parameter Type Description
errorCode Number Error code: 0 means success
errorMessage String Error message
translation json Translation Result

translation结构:

Parameter Type Description
source String original language
target String target language for translation
sourceText String original text
targetText String translation result
  • HTTP response example

          {
                 "errorCode": 0,
                 "translation": {
                    "source": "en",
                    "target": "zh-CN",
                    "sourceText": "hello world",
                    "targetText": "你好世界"
                 }
              }