Skip to content

Register your tool's translation files

Last updated

To use translations in your editor extension, register the folder that holds your translation files as a “source”. Prepare one source per tool.

  1. Create one folder for translation files inside your tool’s folder (for example, Editor/Localization/).

  2. Put one JSON file per language directly in that folder. Name each file with a language-REGION code, such as en-US.json or ja-JP.json.

    Editor/Localization/
    ├── en-US.json
    └── ja-JP.json
  3. In each file, write keys and translated strings as a JSON object.

    {
    "window": {
    "title": "Sample Tool",
    "apply": "Apply"
    }
    }
  4. After Unity imports the folder, open the folder’s .meta file in a text editor and copy the value of guid:.

  • The root must be an object, and values can only be strings, objects, or arrays. Numbers, booleans, and null cause a load error.
  • Nested keys are joined with . into a single key. The example above defines two keys: window.title and window.apply.
  • Refer to array elements by index, such as key.0 and key.1.

The entry point is EditorLocalization.Service (IEditorLocalizationService) in the com.amari_noa.unity_editor_localization_core.editor namespace. Register your source in the static constructor of a class marked with [InitializeOnLoad].

using com.amari_noa.unity_editor_localization_core.editor;
using UnityEditor;
[InitializeOnLoad]
internal static class SampleToolLocalization
{
public const string SourceId = "com.example.sample-tool";
static SampleToolLocalization()
{
EditorLocalization.Service.RegisterSource(new EditorLocalizationSourceDefinition
{
SourceId = SourceId,
DisplayName = "Sample Tool",
LocalizationFolderGuid = "GUID from the translation folder's .meta file",
DefaultLanguageCode = "en-US",
BaseLanguageCode = "en-US"
});
}
}

The fields of EditorLocalizationSourceDefinition are as follows.

Field Description
SourceId A unique string that identifies the source. Required.
DisplayName The display name. Defaults to SourceId.
LocalizationFolderGuid The GUID of the folder that holds the translation files.
DefaultLanguageCode The language to fall back to when a key is missing in the current language. Defaults to en-US if empty or invalid.
BaseLanguageCode The base language for key validation. Defaults to en-US if empty or invalid.
  • Because the folder is specified by GUID rather than path, the reference does not break when the package moves.
  • Registrations are cleared on every domain reload, so register with [InitializeOnLoad] each time.
  • RegisterSource returns a bool that tells whether registration succeeded. Registering the same SourceId twice is rejected and returns false.

Loaded translations are cached, so edits to the JSON files do not show up right away. Call Reload(sourceId) to reload one source, or ReloadAll() to reload every source. A domain reload also reloads them.