2020-04-07

[Unity] Localize - Masamune framework

The Masamune framework is an extension asset for the Unity3D.

Localize - Masamune framework

"Localize - Masamune framework" is one of the "Masamune framework" series.

What is the Masamune framework?

The Masamune framework series will help you create games in Unity3D.

It supports a variety of Unity details, including UI creation, Task management, and Data management etc., and can dramatically speed up game creation.

Each product line in the series is linked but independent and does not compete or cause problems with any one or all assets. Deploying only the plug-ins you want to support will result in better cost and performance.

You can check the current lineup on the following page.

The "UIElements Expansions" series can also be used within "Masamune framework".

This "Localize - Masamune framework" mainly supports the following functions:

  • Translation Support in Unity Runtime
  • Translation Support in Unity Editor
  • Google Spreadsheet Management

Translation Support in Unity Runtime

image block

"Localize - Masamune framework" supports the Unity runtime, that is, in-game translation.

The text translated into the Text component of UnityUI (uGUI) is automatically entered for easy use.

The following languages are available by default.

  • English
  • Japanese
  • Chinese (Simplified)
  • Chinese (Traditional Chinese)
  • French
  • Spanish
  • Italian
  • German
  • Portuguese
  • Russian
  • Korean
  • Thai
  • Indonesian

You can also work with new languages by adding them to your translation files.

Translation Support in Unity Editor

image block

"Localize - Masamune framework" supports translations in the Unity editor using UIElements.

It provides several tags for displaying translated text in UXML tags, making translation easy to use in editor windows and inspectors.

It can also be used with the "UIElements Expansions" series.

Google Spreadsheet Management

image block

"Localize - Masamune framework" treats certain formatted CSV files as translation data.

You can use any tool to create a formatted CSV file, but "Google spreadsheet" is recommended for this asset.

"Google spreadsheet" is a spreadsheet program that runs on the web. The difference from other software that can export CSV files is that you can use "GOOGLETRANSLATE" functions.

The "GOOGLETRANSLATE" function uses the Google Translate engine to automatically translate text from other cells and display the results.

This is very useful because you can translate languages that are difficult for you to handle with one touch.

"Localize - Masamune framework" provides features to support administration with Google Spreadsheets.

How to Use

Import

image block

Purchase from Unity Asset Store.

You can import after purchase from "My Assets".

Translation Support in Unity Runtime

The Unity runtime currently supports the Text component of the UnityUI (uGUI).

First, add a "Text" component to the game object where you want to display the translated text.

Then place the "TextLocalizeApplicator" component in the same game object as the "Text" component you just added.

image block

Enter "Translation ID" in the "Localize Text" field of "TextLocalizeApplicator" to display the translation text corresponding to the device running the game or the language of the Unity editor.

Setting the "Language" item forces the translation to that language. (If there is no corresponding language in the translation data, it is displayed as it is.)

Using from scripts

"TextLocalizeApplicator" can see the source code (Assets/Masamune/Modules/unity.style.localize/Scripts/TextLocalizeApplicator.cs)

public class TextLocalizeApplicator : MonoBehaviour {
    /// <summary>
    /// The text
    /// </summary>
    [SerializeField]
    public UnityEngine.UI.Text text;

    /// <summary>
    /// Gets or sets the icon.
    /// </summary>
    /// <value>The icon.</value>
    public string localizeText {
       get => this._localizeText;
       set {
          this._localizeText = value;
          this.Repaint( );
       }
    }
    [SerializeField]
    private string _localizeText;

    /// <summary>
    /// Gets or sets the language.
    /// </summary>
    /// <value>The language.</value>
    public SystemLanguage language {
       get => this._language;
       set {
          this._language = value;
          this.Repaint( );
       }
    }
    [SerializeField]
    private SystemLanguage _language = SystemLanguage.Unknown;

    /// <summary>
    /// Awakes this instance.
    /// </summary>
    private void Awake( ) {
       if( this.text == null ) this.text = this.GetComponent<UnityEngine.UI.Text>( );
       this.Repaint( );
    }
    /// <summary>
    /// Called when [validate].
    /// </summary>
    private void OnValidate( ) {
       this.Repaint( );
    }

    /// <summary>
    /// Repaints this instance.
    /// </summary>
    public void Repaint( ) {
       if( this.text == null || this.localizeText.IsNullOrEmpty( ) ) return;
       SystemLanguage language = this.language == SystemLanguage.Unknown ? Localize.SystemLanguage : this.language;
       Localize localize = Localize.Get( this.localizeText, language, this.localizeText );
       if( localize == null ) return;
       this.text.font = localize;
       this.text.text = localize;
    }
}

This "Repaint" method can be used for other components.

public void Repaint( ) {
    if( this.text == null || this.localizeText.IsNullOrEmpty( ) ) return;
    SystemLanguage language = this.language == SystemLanguage.Unknown ? Localize.SystemLanguage : this.language;
    Localize localize = Localize.Get( this.localizeText, language, this.localizeText );
    if( localize == null ) return;
    this.text.font = localize;
    this.text.text = localize;
}

Get an object of type Localize with "Localize.Get("Localization ID", Language, DefaultValue)". (Returns null if the specified language and translation ID do not exist)

The Localize type contains the font data and translated characters to display the translation and can be cast to Font and string types, respectively. Place this data in the specified properties of the component.

Be aware that languages that handle special characters such as Japanese and Chinese may not display properly unless both the font and the character are set.

Translation Support in Unity Editor

You can use UIElements to display icons in the Unity editor.

The following UXML tags are available:

Tag Name Summary Usage Examples
engine:LocalizeLabel Translated version of engine:Label <engine:LocalizeLabel text="Localization ID" />
engine:LocalizeButton Translated version of engine:Button <engine:LocalizeButton text="Localization ID" />
engine:LocalizeH1~H6 Translated version of engine:H1~H6 (Tags Added in UIElements Expansion Common Features) <engine:LocalizeH1 text="Localization ID" />
editor:BindableLocalizeLabel Translated version of editor:BindableLabel (Tags Added in UIElements Expansion Common Features) <editor:BindableLocalizeLabel text="Localization ID" binding-path="path" />
editor:BindableLocalizeButton Translated version of editor:BindableButton (Tags Added in UIElements Expansion Common Features) <editor:BindableLocalizeButton text="Localization ID" binding-path="path" />
editor:BindableLocalizeH1~H6 Translated version of editor:BindableH1~H6 (Tags Added in UIElements Expansion Common Features) <editor:BindableLocalizeH2 text="Localization ID" binding-path="path" />

Google Spreadsheet Management

Google Spreadsheets are managed in "LocalizeInfo".

Open "Assets/Masamune/Modules/unit.style.localize/Resources/LocalizeInfo" in the inspector. The "Localization Information" screen appears.

image block

Provides step-by-step instructions on how to create new translation data.

  • Open this "Template" file first.
  • Copy the open template file and save it to your Google Drive.
  • Retrieve and copy the URL of the saved spreadsheet from a browser, etc.
  • Paste the URL you copied in step 3 into "Localization URL" in "Localization Information" in the Unity editor.
  • Click the download button under "Download URL". The CSV file is automatically downloaded onto the Unity project.
  • After that, you can edit the spreadsheet file saved in step 3 following the example, and download the CSV file in step 5 each time you finish editing.

If you get an error in step 5, open the Open button next to the Download button and save it as "Localization.csv" directly under the Unity "Resources" folder.

Summary

You can get the following support by using "Localize - Masamune framework":

  • Translation Support in Unity Runtime
  • Translation Support in Unity Editor
  • Google Spreadsheet Management

Such support will provide the following benefits:

  • Easily access and manage your translations

Please enjoy a comfortable game production life by introducing "Masamune framework" !

If you are interested, please check out the asset store!

Use the Localize - Masamune Framework from mathru.net on your next project. Find this integration tool & more on the Unity Asset Store.
https://assetstore.unity.comhttps://assetstore.unity.com
title
[Unity] IconFont - Masamune framework

Development Unity Masamune AssetStore CSharp

◀︎ Next
[Unity] UIElements Expansions: Navigation

Development Unity UIElements AssetStore CSharp

▶︎ Previous