docs.unity3d.com
    Show / Hide Table of Contents

    Class LocalizationEditorSettings

    Provides methods for configuring Localization settings including tables and Locales.

    Inheritance
    Object
    LocalizationEditorSettings
    Namespace: UnityEditor.Localization
    Syntax
    public class LocalizationEditorSettings : object

    Properties

    ActiveLocalizationSettings

    The LocalizationSettings used for this project and available in the player and editor.

    Declaration
    public static LocalizationSettings ActiveLocalizationSettings { get; set; }
    Property Value
    Type Description
    LocalizationSettings

    EditorEvents

    Localization modification events that can be used when building editor components.

    Declaration
    public static LocalizationEditorEvents EditorEvents { get; }
    Property Value
    Type Description
    LocalizationEditorEvents

    ShowLocaleMenuInGameView

    During play mode, in the editor a menu can be shown to allow for quickly changing the SelectedLocale.

    Declaration
    public static bool ShowLocaleMenuInGameView { get; set; }
    Property Value
    Type Description
    Boolean

    UseLocalizedAssetSearchPicker

    When true the advanced Unity Search picker will be used when selecting LocalizedAsset<TObject> table entries. When false the tree view picker will be used.

    Declaration
    public static bool UseLocalizedAssetSearchPicker { get; set; }
    Property Value
    Type Description
    Boolean

    UseLocalizedStringSearchPicker

    When true the advanced Unity Search picker will be used when selecting LocalizedString table entries. When false the tree view picker will be used.

    Declaration
    public static bool UseLocalizedStringSearchPicker { get; set; }
    Property Value
    Type Description
    Boolean

    Methods

    AddLocale(Locale, Boolean)

    Add the Locale so that it can be used by the Localization system.

    Declaration
    public static void AddLocale(Locale locale, bool createUndo = false)
    Parameters
    Type Name Description
    Locale locale

    The Locale to add to the project so it can be used by the Localization system.

    Boolean createUndo

    Used to indicate if an Undo operation should be created.

    Examples

    This shows how to create a Locale and add it to the project.

        // Create the Locale asset
        var locale = Locale.CreateLocale(SystemLanguage.Spanish);
        AssetDatabase.CreateAsset(locale, "Assets/Spanish.asset");
    
        // Add the Locale to the project
        LocalizationEditorSettings.AddLocale(locale);

    CreateAssetTableCollection(String, String)

    Creates a AssetTableCollection using the project Locales.

    Declaration
    public static AssetTableCollection CreateAssetTableCollection(string tableName, string assetDirectory)
    Parameters
    Type Name Description
    String tableName

    The Table Collection Name to use.

    String assetDirectory

    The directory to store the generated assets.

    Returns
    Type Description
    AssetTableCollection

    The created AssetTableCollection collection.

    Examples

    This example shows how to update a collection by adding a new localized asset.

    public static void AddAssetToCollection(Texture asset)
    {
        var collection = LocalizationEditorSettings.GetAssetTableCollection("My Assets");
        if (collection == null)
        {
            collection = LocalizationEditorSettings.CreateAssetTableCollection("My Assets", "Assets/Asset Tables");
        }
    
        collection.AddAssetToTable(SystemLanguage.English, "My Texture", asset);
    }

    CreateAssetTableCollection(String, String, IList<Locale>)

    Creates a AssetTableCollection using the provided Locales.

    Declaration
    public static AssetTableCollection CreateAssetTableCollection(string tableName, string assetDirectory, IList<Locale> selectedLocales)
    Parameters
    Type Name Description
    String tableName

    The name of the new collection. Cannot be blank or whitespace, cannot contain invalid filename characters, and cannot contain "[]".

    String assetDirectory

    The directory to store the generated assets.

    IList<Locale> selectedLocales

    The locales to generate the collection with. A AssetTable will be created for each Locale

    Returns
    Type Description
    AssetTableCollection

    The created AssetTableCollection collection.

    CreateCollectionFromLooseTables(IList<LocalizationTable>, String)

    Creates a StringTableCollection or AssetTableCollection from the provided loose tables.

    Declaration
    public static LocalizationTableCollection CreateCollectionFromLooseTables(IList<LocalizationTable> looseTables, string path)
    Parameters
    Type Name Description
    IList<LocalizationTable> looseTables

    Tables to create the collection from. All tables must be of the same type.

    String path

    The path to save the new assets to.

    Returns
    Type Description
    LocalizationTableCollection

    The created StringTableCollection or AssetTableCollection.

    CreateStringTableCollection(String, String)

    Creates a StringTableCollection using the project Locales.

    Declaration
    public static StringTableCollection CreateStringTableCollection(string tableName, string assetDirectory)
    Parameters
    Type Name Description
    String tableName

    The name of the new collection. Cannot be blank or whitespace, cannot contain invalid filename characters, and cannot contain "[]".

    String assetDirectory

    The directory to save the generated assets, must be in the project Assets directory.

    Returns
    Type Description
    StringTableCollection

    The created StringTableCollection collection.

    Examples

    This example shows how to create a new StringTableCollection and add some English values.

        var newCollection = LocalizationEditorSettings.CreateStringTableCollection("My Strings", "Assets/String Tables");
    
        var table = newCollection.GetTable("en") as StringTable;
        table.AddEntry("START_MENU", "Start Game");
        table.AddEntry("OPTIONS_MENU", "Options");
        table.AddEntry("EXIT_MENU", "Quit");
    
        // Mark modified assets dirty so changes are saved.
        EditorUtility.SetDirty(table);
        EditorUtility.SetDirty(table.SharedData);

    CreateStringTableCollection(String, String, IList<Locale>)

    Creates a StringTableCollection using the provided Locales.

    Declaration
    public static StringTableCollection CreateStringTableCollection(string tableName, string assetDirectory, IList<Locale> selectedLocales)
    Parameters
    Type Name Description
    String tableName

    The name of the new collection. Cannot be blank or whitespace, cannot contain invalid filename characters, and cannot contain "[]".

    String assetDirectory

    The directory to save the generated assets, must be in the project Assets directory.

    IList<Locale> selectedLocales

    The locales to generate the collection with. A StringTable will be created for each Locale.

    Returns
    Type Description
    StringTableCollection

    The created StringTableCollection collection.

    Examples

    This example shows how to create a new StringTableCollection which contains an English and Japanese StringTable.

        var english = LocalizationEditorSettings.GetLocale("en-GB");
        var japanese = LocalizationEditorSettings.GetLocale(SystemLanguage.Japanese);
    
        // Create a collection with a English (UK) and Japanese table
        var newCollection = LocalizationEditorSettings.CreateStringTableCollection("My Strings", "Assets/String Tables", new List<Locale> { english, japanese });
    
        var table = newCollection.GetTable("en") as StringTable;
        table.AddEntry("START_MENU", "Start Game");
        table.AddEntry("OPTIONS_MENU", "Options");
        table.AddEntry("EXIT_MENU", "Quit");

    FindLooseStringTablesUsingSharedTableData(SharedTableData, IList<LocalizationTable>)

    If a table does not belong to a LocalizationTableCollection then it is considered to be loose, it has no parent collection and will be ignored. This returns all loose tables that use the same SharedTableData, they could then be converted into a LocalizationTableCollection using CreateCollectionFromLooseTables(IList<LocalizationTable>, String).

    Declaration
    public static void FindLooseStringTablesUsingSharedTableData(SharedTableData sharedTableData, IList<LocalizationTable> foundTables)
    Parameters
    Type Name Description
    SharedTableData sharedTableData
    IList<LocalizationTable> foundTables

    FindSimilarKey(String)

    Returns the AssetTableCollection that contains a table entry with the closest match to the provided text. Uses the Levenshtein distance method.

    Declaration
    public static (StringTableCollection collection, SharedTableData.SharedTableEntry entry, int matchDistance) FindSimilarKey(string keyName)
    Parameters
    Type Name Description
    String keyName
    Returns
    Type Description
    (, , )<StringTableCollection, SharedTableData.SharedTableEntry, Int32>

    GetAssetTableCollection(TableReference)

    Returns a AssetTableCollection with the matching TableReference.

    Declaration
    public static AssetTableCollection GetAssetTableCollection(TableReference tableNameOrGuid)
    Parameters
    Type Name Description
    TableReference tableNameOrGuid
    Returns
    Type Description
    AssetTableCollection

    Found collection or null if one could not be found.

    Examples

    This example shows how to update a collection by adding a new localized asset.

    public static void AddAssetToCollection(Texture asset)
    {
        var collection = LocalizationEditorSettings.GetAssetTableCollection("My Assets");
        if (collection == null)
        {
            collection = LocalizationEditorSettings.CreateAssetTableCollection("My Assets", "Assets/Asset Tables");
        }
    
        collection.AddAssetToTable(SystemLanguage.English, "My Texture", asset);
    }

    GetAssetTableCollections()

    Returns all AssetTableCollection assets that are in the project.

    Declaration
    public static ReadOnlyCollection<AssetTableCollection> GetAssetTableCollections()
    Returns
    Type Description
    ReadOnlyCollection<AssetTableCollection>
    Examples

    This example shows how to print out the contents of all the AssetTableCollection in the project.

    [MenuItem("Localization Samples/Print All Asset Table Collection Contents")]
    public static void PrintAssetTableCollectionContents()
    {
        // This example prints out the contents of every Asset Table Collection
        var stringBuilder = new StringBuilder();
        foreach (var stringTableCollection in LocalizationEditorSettings.GetAssetTableCollections())
        {
            stringBuilder.AppendLine($"String Table Collection Name: {stringTableCollection.TableCollectionName}");
            foreach (var assetTable in stringTableCollection.AssetTables)
            {
                stringBuilder.AppendLine($"\tTable {assetTable.LocaleIdentifier}");
                foreach (var assetTableValue in assetTable.Values)
                {
                    // Load the asset
                    Object asset = null;
                    if (!string.IsNullOrEmpty(assetTableValue.Guid))
                    {
                        var assetPath = AssetDatabase.GUIDToAssetPath(assetTableValue.Guid);
                        asset = AssetDatabase.LoadAssetAtPath<Object>(assetPath);
                    }
    
                    stringBuilder.AppendLine($"\t\t{assetTableValue.Key} - {asset}");
                    if (assetTable.MetadataEntries.Count > 0)
                    {
                        foreach (var metadataEntry in assetTable.MetadataEntries)
                        {
                            stringBuilder.AppendLine($"\t\t\t{metadataEntry}");
                        }
                    }
                }
            }
        }
    
        Debug.Log(stringBuilder.ToString());
    }

    GetCollectionForSharedTableData(SharedTableData)

    Returns the LocalizationTableCollection that the SharedTableData is part of or null if one could not be found.

    Declaration
    public static LocalizationTableCollection GetCollectionForSharedTableData(SharedTableData sharedTableData)
    Parameters
    Type Name Description
    SharedTableData sharedTableData

    The shared table data to match against a collection.

    Returns
    Type Description
    LocalizationTableCollection

    The found collection or null if one could not be found.

    GetCollectionFromTable(LocalizationTable)

    Returns the LocalizationTableCollection that the table is part of or null if the table has no collection.

    Declaration
    public static LocalizationTableCollection GetCollectionFromTable(LocalizationTable table)
    Parameters
    Type Name Description
    LocalizationTable table

    The table to find the collection for.

    Returns
    Type Description
    LocalizationTableCollection

    The found collection or null if one could not be found.

    GetLocale(LocaleIdentifier)

    Returns the locale that matches the LocaleIdentifier"/> in the project.

    Declaration
    public static Locale GetLocale(LocaleIdentifier localeId)
    Parameters
    Type Name Description
    LocaleIdentifier localeId
    Returns
    Type Description
    Locale

    The found Locale or null if one could not be found.

    Examples

    This example shows how to find a Locale using a SystemLanguage or code.

        // Find a Spanish Locale using the SystemLanguage
        var spanish = LocalizationEditorSettings.GetLocale(SystemLanguage.Spanish);
    
        // Find a Spanish (Mexico) Locale using the code
        var spanishMexico = LocalizationEditorSettings.GetLocale("es-MX");

    GetLocales()

    Returns all Locale that are part of the Localization system and will be included in the player. To Add Locales use AddLocale(Locale, Boolean) and RemoveLocale(Locale, Boolean) to remove them. Note this does not include PseudoLocale which can be retrieved by using GetPseudoLocales().

    Declaration
    public static ReadOnlyCollection<Locale> GetLocales()
    Returns
    Type Description
    ReadOnlyCollection<Locale>

    A collection of all Locales in the project.

    Examples

    This example prints the names of the Locales.

        foreach (var locale in LocalizationEditorSettings.GetLocales())
        {
            Debug.Log(locale.LocaleName);
        }

    GetPreloadTableFlag(LocalizationTable)

    Returns true if the table is marked for preloading.

    Declaration
    public static bool GetPreloadTableFlag(LocalizationTable table)
    Parameters
    Type Name Description
    LocalizationTable table

    The table to query.

    Returns
    Type Description
    Boolean

    true if preloading is enable otherwise false.

    Examples

    This example shows how to query if a table is marked as preload.

        var collection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
    
        var englishTable = collection.GetTable("en");
        Debug.Log($"Preload: {LocalizationEditorSettings.GetPreloadTableFlag(englishTable)}");

    GetPseudoLocales()

    Returns all PseudoLocale that are part of the Localization system and will be included in the player.

    Declaration
    public static ReadOnlyCollection<PseudoLocale> GetPseudoLocales()
    Returns
    Type Description
    ReadOnlyCollection<PseudoLocale>

    GetStringTableCollection(TableReference)

    Returns a StringTableCollection with the matching TableReference.

    Declaration
    public static StringTableCollection GetStringTableCollection(TableReference tableNameOrGuid)
    Parameters
    Type Name Description
    TableReference tableNameOrGuid
    Returns
    Type Description
    StringTableCollection

    Found collection or null if one could not be found.

    Examples

    This example shows how to update a collection by adding support for a new Locale.

        // Create the new Locale
        var locale = Locale.CreateLocale(SystemLanguage.Spanish);
        AssetDatabase.CreateAsset(locale, "Assets/Spanish.asset");
        LocalizationEditorSettings.AddLocale(locale);
    
        // Get the collection
        var collection = LocalizationEditorSettings.GetStringTableCollection("My String Table");
    
        // Add a new table
        var newTable = collection.AddNewTable(locale.Identifier) as StringTable;
    
        // Add a new entry to the table
        var entry = newTable.AddEntry("Hello", "Hola");
    
        // Add some metadata
        entry.AddMetadata(new Comment { CommentText = "This is a comment"});
    
        // We need to mark the table and shared table data entry as we have made changes
        EditorUtility.SetDirty(newTable);
        EditorUtility.SetDirty(newTable.SharedData);

    GetStringTableCollections()

    Returns all StringTableCollection that are in the project.

    Declaration
    public static ReadOnlyCollection<StringTableCollection> GetStringTableCollections()
    Returns
    Type Description
    ReadOnlyCollection<StringTableCollection>
    Examples

    This example shows how to print out the contents of all the StringTableCollection in the project.

    [MenuItem("Localization Samples/Print All String Table Collection Contents")]
    public static void PrintStringTableCollectionContents()
    {
        // This example prints out the contents of every String Table Collection
        var stringBuilder = new StringBuilder();
        foreach (var stringTableCollection in LocalizationEditorSettings.GetStringTableCollections())
        {
            stringBuilder.AppendLine($"String Table Collection Name: {stringTableCollection.TableCollectionName}");
            foreach (var stringTable in stringTableCollection.StringTables)
            {
                stringBuilder.AppendLine($"\tTable {stringTable.LocaleIdentifier}");
                foreach (var stringTableValue in stringTable.Values)
                {
                    stringBuilder.AppendLine($"\t\t{stringTableValue.Key} - {stringTableValue.LocalizedValue}");
                    if (stringTableValue.MetadataEntries.Count > 0)
                    {
                        foreach (var metadataEntry in stringTableValue.MetadataEntries)
                        {
                            stringBuilder.AppendLine($"\t\t\t{metadataEntry}");
                        }
                    }
                }
            }
        }
    
        Debug.Log(stringBuilder.ToString());
    }

    RemoveLocale(Locale, Boolean)

    Removes the locale from the Localization system.

    Declaration
    public static void RemoveLocale(Locale locale, bool createUndo = false)
    Parameters
    Type Name Description
    Locale locale

    The Locale to remove so that it is no longer used by the Localization system.

    Boolean createUndo

    Used to indicate if an Undo operation should be created.

    Examples

    This shows how to remove a Locale from the project.

        // Find the Locale
        var locale = LocalizationEditorSettings.GetLocale("en");
    
        // Remove it from the Localization system
        LocalizationEditorSettings.RemoveLocale(locale);

    SetPreloadTableFlag(LocalizationTable, Boolean, Boolean)

    Adds or Remove the preload flag for the selected table.

    Declaration
    public static void SetPreloadTableFlag(LocalizationTable table, bool preload, bool createUndo = false)
    Parameters
    Type Name Description
    LocalizationTable table

    The table to mark as preload.

    Boolean preload

    true ifd the table should be preloaded or false if it should be loaded on demand.

    Boolean createUndo

    Should an Undo record be created?

    Examples

    This example shows how to set the preload flag for a single collection.

        var collection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
    
        // Enable preloading for all tables in the collection
        foreach (var table in collection.StringTables)
        {
            LocalizationEditorSettings.SetPreloadTableFlag(table, true);
        }
    In This Article
    • Properties
      • ActiveLocalizationSettings
      • EditorEvents
      • ShowLocaleMenuInGameView
      • UseLocalizedAssetSearchPicker
      • UseLocalizedStringSearchPicker
    • Methods
      • AddLocale(Locale, Boolean)
      • CreateAssetTableCollection(String, String)
      • CreateAssetTableCollection(String, String, IList<Locale>)
      • CreateCollectionFromLooseTables(IList<LocalizationTable>, String)
      • CreateStringTableCollection(String, String)
      • CreateStringTableCollection(String, String, IList<Locale>)
      • FindLooseStringTablesUsingSharedTableData(SharedTableData, IList<LocalizationTable>)
      • FindSimilarKey(String)
      • GetAssetTableCollection(TableReference)
      • GetAssetTableCollections()
      • GetCollectionForSharedTableData(SharedTableData)
      • GetCollectionFromTable(LocalizationTable)
      • GetLocale(LocaleIdentifier)
      • GetLocales()
      • GetPreloadTableFlag(LocalizationTable)
      • GetPseudoLocales()
      • GetStringTableCollection(TableReference)
      • GetStringTableCollections()
      • RemoveLocale(Locale, Boolean)
      • SetPreloadTableFlag(LocalizationTable, Boolean, Boolean)
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023