Localization of games and applications in Unity. Quick and convenient

  • Tutorial
Hello! In this article, I will share my experience in localizing games and applications in Unity, as well as talk about my Simple Localization plugin, which is available in the Asse Store. The article level is Easy. There will be no code at all, it will not be useful to you.



From the point of view of the general concept, everything is simple. We should have a list of dictionaries for each language with the same keys, from which we will get localized values. On the technical side, you need to determine:

  • What will our dictionaries be?
  • Where will they be stored?
  • How will we edit and expand them?
  • How to implement a bundle with the application interface?

When implementing, I was guided by two principles: simplicity and convenience. So, the simplest structured format that is suitable for dictionaries is CSV (Comma Separated Values). This is a text file in which all cells are separated by a separator - either a comma (",") or a semicolon (";"), depending on the regional settings. CSV can be opened and edited in any text editor, but Excel is best for this. CSV will be stored, of course, in the Resources folder so that the application can read them at any time.

The format will be as follows: the first column is the keys, all subsequent columns are the dictionaries. The first line is the heading. You can have one common CSV, if there are not many texts in the application, but you can split it into several CSVs according to some principle, for example: menu, settings, achievements, etc.

Go ahead. Editing the localization in Excel is great, of course, but I suggest uploading them to Google Sheets. Then you can edit them from any place, at any time and from any device. But the most important thing is that localization can be shared with translators, and they will not have any difficulties with translation. You can look at the dictionary by reference .


And the last point is integration with Unity, with uGUI. Here, too, everything is simple - for each text component Text we will add our LocalizedText component , in which we will specify the key. When launched, this component will receive a localized value and set it to Text .



Then a few questions arise:

  • How and when to initialize the dictionary? It is enough to make a call to LocalizationManager.Read from the control script. This can be done in Awake or Start, if you are satisfied with the automatic language detection ( Application.systemLanguage ), or after loading the profile, when the user settings are already known.
  • What if we don’t know in advance exactly what the Text component will have ? We do not add the LocalizedText component , and then assign it a value from the code by accessing the dictionary via LocalizationManager.Localize (string localizationKey) .
  • What to do if you need to insert a parameter into a localized value? We simply use formatting in the localized string, for example, “Level {0}”, and then we perform a substitution through string.Format. There is an overload of LocalizationManager.Localize (string localizationKey, params object [] args) for this .
  • How to change localization at runtime? Just change the language through LocalizationManager.Language. This will trigger an event for which all the components of LocalizedText are subscribed . However, Text components localized from the code (which do not have the LocalizedText component ) will need to be updated manually.
  • What to do, with other elements, for example, with the dropdown Dropdown list ? Obviously, use the component LocalizedDropdown =)

Well, the last thing in my asset is that he can automatically download all the sheets from Google Sheets and save them in game resources. To do this, there is the LocalizationSync component , which has a Sync button (in the inspector).

You can download it in the Asset Store: Simple Localization .

Also popular now: