TranslationManager - Manage Languages & Translations in Unity

Translations are always an important issue in game development. Many players will not know your local language or English. So you'll want to support as many languages as possible, or at least the largest language groups. But what's the best way to manage translations in Unity? For simple texts, the TranslationManager has worked well for me.

This is how the TranslationManager works

This module provides a manager for translating strings in your application. You can register different languages and switch between them. The translations are stored in JSON or CSV files. The manager automatically loads the right file for the language. Behaviours then automatically translate text fields using the service, for example.

Translation files are loaded using addressable assets. Therefore, you must specify the base address of the translation files. This can be the folder where all files are stored. The manager will try to load the corresponding translation file by its addressable name. The addressable name must be the same as the language code you specify when registering a language.

You can register new languages:

TranslationManager.service?.RegisterLanguage("en", SystemLanguage.English);
TranslationManager.service?.RegisterLanguage("de", SystemLanguage.German);

You can now switch to a certain language:

TranslationManager.service?.ChangeLanguage("en");

The following translation files would be loaded:

/your/base/path/de

The translation service will try to guess, if the file is in JSON or CSV format. Only simple key-value-maps are supported.

You can get a translation string by using the Get() method:

TranslationManager.service?.Get("myKey");

If the translation string is not found, the key will be returned and an error will be logged.

Translation strings can contain variables. You can pass these variables to the Get() method:

var variables = new Dictionary<string, string>();
variables.Add("username", "Alfred");
TranslationManager.service?.Get("welcome", variables);

Given the translation string is defined as this:

{
    "welcome": "Welcome :username!"
}

The following string will be returned:

"Willkommen Alfred!"

You can also get the current language:

var currentLanguage = TranslationManager.service?.language;

You can check if a certain language is registered:

var isRegistered = TranslationManager.service?.IsRegistered("en");
var isRegistered = TranslationManager.service?.IsRegistered(SystemLanguage.English);

Your Feedback is important!

What do you think of the services presented here? Is there anything missing or does something not work as expected? As always, I'm happy to listen to your feedback. Let me know what you think about this module. You can use the comment section below the article for this. You can also find other ways to contact me here. If you found a bug or want an enhancement, please create an issue in the GitHub repository. Further documentation can be found in the README of the corresponding module.

There are no comments yet.