Localization - SebastianKErben/SKE.Unity3D GitHub Wiki

The Localization namespace contains multiple classes but probably only the Translator class which is derived from SingletonEternal will be of interest to you. But before you can use the Translator, you need to create a translation dictionary first. This can be done by right clicking inside a Resources folder and selecting Create -> SKE -> Dictionary.

The standard name of the file will be "Dictionary" but you can change that if you want. The Dictionary can be edited in the Inspector panel of Unity3D and it works like this:

Every Dictionary contains a number of Translations. It's recommended to set this to 1 first for you first language and once your translation is finished, change the number to the number of languages you will support in your game. That way, the first language translation will be copied into the new translations which means you won't need to add all the entries again.

Every Translation is marked as a certain entry from the Unity3D enum SystemLanguage and contains a number of entries. Those entries consist of an Id which needs to be unique as well as the actual Content of the entry which is a text.

Once your translation dictionary exists in a Resource folder, you can start to use the Translator singleton. The default dictionary the Translator attempts to load is "Dictionary" but as written before, you can freely chose the name of your translation dictionary. If you use something different, you need to tell the Translator via

Translator.Instance.CurrentDictionary 

which takes a string representing the name of the translation dictionary asset. You can also set the current language of the Translator with

Translator.Instance.CurrentLanguage

which takes a value from the Unity3D SystemLanguage enum. Whenever you set a new language, the event

Translator.LanguageChanged 

is fired which you can subscribe to. This is useful for example for updating your interface at once as soon as the language is changed. To get text content from the translation dictionary, just call

Translator.Instance.GetTranslation(string id)

which will return a string containing the translation entry for the given id. If you want to get an entry for a different language without changing the current language of the Translator, you can call

Translator.Instance.GetTranslation(string id, SystemLanguage language)

This can be useful for debugging purposes. You can find an example in Examples/Localization and unit tests in Editor/Tests/Localization