Multilingual editor support

Behavior attributes and editor extensions can support multiple languages.

Preparing language files

In order to support multiple languages, it is necessary to add each language file.

Also, register the folder where the language file is placed.

Since language files can only be used in the editor, place them in the Editor folder.

LanguagePath

Placing a language file To register a folder, place the LanguagePath asset in a folder.

  • Select the folder to place in the Project window and right-click.
  • Select “Create > Arbor > Editor > LanguagePath” from the menu.
  • As there are no particular restrictions on the name, please give me the name you like.

Create language file

If you create a file of “Language name.txt” in the folder where the LanguagePath asset is placed, it will be recognized as a language file.

“Language name” must have the same name as the value of the SystemLanguage enumerator.

Unity ScriptReference : SystemLanguage

Writing a language file

In the language file, write it in the format of “word key: display character string” line by line.

Also, if the line head is “//” it is regarded as a comment and that line is ignored.

For example, create Japanese.txt and fill in as follows.

1
2
3
4
// ボスの挙動関連
Menu_ExampleBossAttack: 多言語対応/ボスの攻撃
ExampleBossAttack: ボスの攻撃
ExampleBossDefense: ボスの防御

Next, create English.txt and fill it in as follows.

1
2
3
4
// Boss behavior related
Menu_ExampleBossAttack: Localization/Boss's attack
ExampleBossAttack: Boss's attack
ExampleBossDefense: Boss's defense

Example of folder structure

  • Assets
    • Editor
      • Languages
        • LanguagePath.asset
        • English.txt
        • Japanese.txt

Language word reference

Reference from editor extension

To reference from an editor extension, use ArborEditor.Localization.GetWord() or GetTextContent().

Example script of editor extension

TestLocalizationBehaviour.cs
1
2
3
4
5
6
7
using UnityEngine;
using Arbor;

[AddComponentMenu("")]
public class TestLocalizationBehaviour : StateBehaviour
{
}
TestLocalizationBehaviourEditor.cs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
using UnityEditor;
using ArborEditor;

[CustomEditor(typeof(TestLocalizationBehaviour))]
public class TestLocalizationBehaviourEditor : Editor
{
	public override void OnInspectorGUI()
	{
		EditorGUILayout.LabelField(Localization.GetWord("ExampleBossAttack"));
		EditorGUILayout.LabelField(Localization.GetWord("ExampleBossDefense"));
	}
}

Display example of editor extension

References in behavior attributes

If you set the localization field to true on AddBehaviourMenu or Behavior Title, it will be referenced from the language file.

Example script using attributes

1
2
3
4
5
6
7
8
9
using UnityEngine;
using Arbor;

[AddComponentMenu("")]
[AddBehaviourMenu("Menu_ExampleBossAttack",localization=true)]
[BehaviourTitle("ExampleBossAttack",localization =true)]
public class ExampleBossAttackBehaviour : StateBehaviour
{
}

Display example using attributes

English

Japanese