Translation (Localization)

SkillfulAPI.Translate

Overview

The Translation class provides functionality to translate text from one language to another using the SkillfulAI API. This can be useful for localizing game content, providing multilingual support, or adapting text for different audiences.

Class Definition

using SkillfulAI.API;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Translation : MonoBehaviour
{
    /// <summary>
    /// Unity's Start method, called when the script is initialized. Initiates the translation process.
    /// </summary>
    private void Start()
    {
        Translate();
    }

    /// <summary>
    /// Initiates text translation from English to French using a specified input text.
    /// </summary>
    public void Translate()
    {
        // Input text to be translated
        string inputText = "Now I can seamlessly translate game content!";

        // Perform translation from English to French. Choose different language pairs if required.
        SkillfulAPI.Translate(inputText, LanguagePairs.LanguagePair.EnglishToFrench, result =>
        {
            Debug.Log(result);
        });
    }
}

Detailed Explanation

Start Method

Description: Unity's Start method is called when the script is first initialized. This method triggers the translation process.

Code:

private void Start()
{
    Translate();
}

Functionality:

  • Automatically invokes the Translate method when the script starts.

  • Suitable for initializing translation tasks or performing actions as soon as the script is activated.

Translate Method

Description: The Translate method sends a specified input text to the SkillfulAI API for translation from English to French and logs the result.

Code:

public void Translate()
{
    // Input text to be translated
    string inputText = "Now I can seamlessly translate game content!";

    // Perform translation from English to French. Choose different language pairs if required.
    SkillfulAPI.Translate(inputText, LanguagePairs.LanguagePair.EnglishToFrench, result =>
    {
        Debug.Log(result);
    });
}

Functionality:

  • Sends the input text to the SkillfulAI API for translation.

  • Translates the text from English to French. You can adjust the language pair if needed.

  • Logs the translated text received from the API response.

Usage Example

  1. Add the Script to a GameObject:

    • Attach the Translation script to any GameObject in your Unity scene.

  2. Run the Scene:

    • Upon starting the scene, the Translate method will be invoked automatically.

    • The specified input text will be sent to the SkillfulAI API, and the translated text will be logged to the console.

Conclusion

The Translation function provides a straightforward implementation of text translation using the SkillfulAI Gaming SDK. By translating text between languages, you can easily localize content and enhance the accessibility of your Unity project.

Last updated