Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

L10n.Tr

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static string Tr(string str);

Parameters

Parameter Description
str Original text, basically English.

Returns

string Localized text.

Description

This function referes a po file like ja.po as an asset. Asmdef and [assembly: UnityEditor.Localization] is needed.

Unity takes the group from the LocalizationAttribute on the calling assembly. If that assembly has no attribute, Unity uses the Editor's own translations.

Note: On the CoreCLR scripting backend, Unity can't reliably identify the calling assembly, because the JIT compiler can inline the caller and remove its stack frame. Use the overload that takes a group name and pass one explicitly to avoid this. For text belonging to the Editor itself rather than to an assembly carrying its own translations, pass a null or empty group name.

using UnityEngine;
using UnityEditor;

// This is not an editor script. public class MyScript : MonoBehaviour {}

[CustomEditor(typeof(MyScript))] public class MyScriptInspector : Editor { MyScript m_Target = null; void OnEnable() { m_Target = target as MyScript; }

public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorGUILayout.LabelField(L10n.Tr("Cancel")); } }

Declaration

public static string[] Tr(string[] str_list);

Parameters

Parameter Description
str_list Original texts, basically English.

Returns

string[] Localized texts, in the same order as str_list. Strings with no translation stay unchanged.

Description

Translates an array of strings, using the localization group of the assembly that calls this method.

Every string in the array uses the same group, which Unity identifies once per call.

Note: This has the same CoreCLR limitation as the single string overload. Use the overload that takes a group name.


Declaration

public static string Tr(string str, string groupName);

Parameters

Parameter Description
str Original text, basically English.
groupName Localization group to look the string up in.

Returns

string Localized text, or str itself when no translation exists.

Description

Translates a string in the localization group you name.

This overload names the group directly instead of identifying the calling assembly, so it behaves the same on every scripting backend. Use it wherever the group matters.

The group name is the one you give to LocalizationAttribute on the assembly that holds the translations, or that assembly's name when the attribute names no group. A null or empty group name reads the Editor's own translations.