Tr
This function referes a po file like ja.po as an asset. Asmdef and [assembly: UnityEditor.Localization] is needed.
Read time 3 minutesLast updated 8 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
Tr(string)
This function referes a po file like ja.po as an asset. Asmdef and [assembly: UnityEditor.Localization] is needed.
public static string Tr(string str)
Parameters
Original text, basically English.
Returns
Type | Description |
|---|---|
| string | Localized text. |
Remarks
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.
Examples
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")); }}
Tr(string[])
Translates an array of strings, using the localization group of the assembly that calls this method.
public static string[] Tr(string[] str_list)
Parameters
Original texts, basically English.
Returns
Type | Description |
|---|---|
| string[] | Localized texts, in the same order as |
Remarks
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.
Tr(string, string)
Translates a string in the localization group you name.
public static string Tr(string str, string groupName)
Parameters
Returns
Type | Description |
|---|---|
| string | Localized text, or |
Remarks
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 rather than a package group.
Tr(string[], string)
Translates an array of strings in the localization group you name.
public static string[] Tr(string[] str_list, string groupName)
Parameters
Returns
Type | Description |
|---|---|
| string[] | Localized texts, in the same order as |
Remarks
Every string in the array uses the group you name, so this behaves the same on every scripting backend. A null or empty group name reads the Editor's own translations rather than a package group.