Localization¶
We let you import/export and work with all of your localization right in the Data Editor.
When you create a new parameter, instead of selecting type String, make it Localized String. Every time, when you try to access this parameter in the code, it'll instantly give you an already localized value.
Let's say you have a pair "Key": "LocalizedValue":
- You create a new parameter with the type Localized String.
- In the document you create new key or chose existing one.
- When you access your parameter from the code, you will be getting LocalizedValue instead of Key.
- You can add new strings and their translations on separate page.
Section for programmers¶
If you need to request all available Localizations, use GetAllAvailableLanguages
, it returns the dictionaries with keys: en, fr, ru, zh-CN, ...
var allLocs = Balancy.Localization.Manager.GetAllAvailableLanguages();
If you are using our plugin as is, you will get localized string of the Key when trying to get it.
Otherwise, if you are using some other solution to store all the keys, in order to make everything work, you need override Balancy method of getting localized values:
Balancy.Localization.Manager.OverloadLocalizationRequests((key)=>{
return YOUR_DICTIONARY[key];
});
To change localization use ChangeLocalization
method. As the parameter you need to pass one of the keys from the allLocs dictionary.
var allLocs = Balancy.Localization.Manager.ChangeLocalization(localizationCode);
To read the active localization code:
var activeLocale = Balancy.Localization.Manager.ActiveLocaleCode;
To get localized value for the key use the following method. If the key doesn't exists, we'll return the key as value.
var localizedValue = Balancy.Localization.Manager.Get(key);
Export and import into spreadsheets¶
From the localization strings page you can export and import all strings into spreadsheets. We use the same format as I2Localization plugin for Unity.
Column naming
Column name should include language code braced with []
, e. g. English [en].
To make it works, you need:
- Open your spreadsheet and share editing access with google-sheets-api@balancy-334816.iam.gserviceaccount.com account.
- Copy spreadsheet id.
- Open settings localization page. Set spreadsheet id on the settings page.
UI¶
If you are using a lot of UnityEngine.UI.Text with static text, you'll find very helpful our Component: LocalizationText.cs. Just add it to your GameObject and set the parameter Localization Key value as your Key. It'll automatically put Localized value as Text when you launch the game.
We have the same Component for Text Mesh Pro. You can download it from here