Localization Manager

Presented via ILocalizationManager interface, this system processes localization in your project.

Currently Localization Manager supports only localization files in *.txt format with key=value pairs inside. But in future we're planning to extend this system functionality, so it will support more localization data formats.

To use this system, inject ILocalizationManager interface into your class, as shown below:

[Inject] private ILocalizationManager localizationManager;

Available methods

void SwitchLanguage(SystemLanguage lang)

This method switches current language to the needed one, passed via lang parameter.

Example:

localizationManager.SwitchLanguage(SystemLanguage.French);

string GetLocalizedString(string id)

This method returns localized string with id localization key. If this key is not presented in localization table, it just returns id.

Example:

resultLabel.text = localizationManager.GetLocalizedString("Success");

string GetLocalizedString<T>(string id, params T[] args)

This method returns localized string with id localization key and custom parameters args. If this key is not presented in localization table, it just returns id. Parameters can have any types, convertable to string. In localization table parameters are presented as {0}, {1}, ... {N} terms.

Example:

Localization key and value
Attempt=Attempt {0}
Getting localized string
attemptLabel.text = localizationManager.GetLocalizedString("Attempt", attemptNumber);

So, in case if attemptNumber = 3, this method returns:

Attempt 3

string GetLocalizedString<T>(string id, Color paramsColor, params T[] args)

This method returns localized string with id localization key and custom parameters args. If this key is not presented in localization table, it just returns id. Parameters can have any types, convertable to string. In localization table parameters are presented as {0}, {1}, ... {N} terms. Parameters in localized string will be shown with text color equal to paramsColor.

Example:

attemptLabel.text = localizationManager.GetLocalizedString("Attempt", Color.green, attemptNumber);

void ResolveTexts()

This method finds and translates all Text, TMP_Text and TextMesh components in project. It processes them only in case if that GameObjects also have LangText component with assigned localization key. This method is automatically called right after calling SwitchLanguage method.


List<SystemLanguage> GetAvailableLanguages()

This method returns list of available languages in project (languages which have their translation files in Assets/Resources/Localization folder).


SystemLanguage GetCurrentLanguage()

This method returns current language in game.

Last updated