Table of Contents

Class Localizer

Provides a way to translate language lookup keys into localized strings.

public sealed class Localizer
Inheritance
Localizer
Inherited Members

Constructors

Localizer(string, Func<List<LocalizationAsset>>)

Constructs a localizer based on a list of LocalizationAssets.

public Localizer(string defaultLanguage, Func<List<LocalizationAsset>> assetLoader)

Parameters

defaultLanguage string

The default language code to use as a fallback when strings are missing

assetLoader Func<List<LocalizationAsset>>

A function which loads LocalizationAssets

Localizer(string, Func<List<(string, Func<string, string>)>>)

Constructs a Localizer based on a callback which loads from some external source of localizations. The function is expected to return a list of (language, lookup) pairs, where lookup is a function which attempts to look up a single string by its key, returning null if not found.

This function may be called multiple times if localizations are reloaded.

public Localizer(string defaultLanguage, Func<List<(string, Func<string, string>)>> loader)

Parameters

defaultLanguage string

The default language code to use as a fallback when strings are missing

loader Func<List<(string, Func<string, string>)>>

Properties

DefaultLanguage

The default (fallback) language to use to look up keys when they are missing in the currently selected UI language.

public string DefaultLanguage { get; }

Property Value

string

Methods

GetLocalizedString(string)

Obtains a localized string, or a placeholder if it cannot be found.

public string GetLocalizedString(string key)

Parameters

key string

Returns

string

LocalizeUIElements(VisualElement)

Localizes UI elements under the given root element. Any elements with the class "ndmf-tr" will be localized automatically, with localization keys under their text or label properties being converted into localized strings. These elements will automatically update when the currently selected language changes.

public void LocalizeUIElements(VisualElement root)

Parameters

root VisualElement

ReloadLocalizations()

Reloads all localizations from their loader functions.

public static void ReloadLocalizations()

TryGetLocalizedString(string, out string)

Attempts to look up a localized string. Returns true if the string was found, false otherwise.

public bool TryGetLocalizedString(string key, out string value)

Parameters

key string
value string

Returns

bool