UnityLocalizationManager

February 12, 2019 ยท View on GitHub

Localization system to manage multiple languages including date time, currencies, and other informations that change depending on current language.

How to use

you can find a pratical example inside this repository in PoolingScene scene

1 - Exporta a CSV file with all the languages and translations (use this file as base)

2 - Place the file wherever you want in the project and change the path in LocalizationManager constructor

public LocalizationManager(string filePath = "PATH/TO/FILE.CSV")
{

3 - The project will initially use the system language as default. If you wish to change, use LocalizationManager.Instance.ChangeLanguage using the language code or Locale (you can find/add Locales in Locale.cs

LocalizationManager.Instance.ChangeLanguage("en_US");

4 - To get a localized text, use LocalizationManager.Instance.Get. You can also use parameters (explained below)

LocalizationManager.Instance.ChangeLanguage("es_ES");
var localizedHello = LocalizationManager.Instance.Get("hello"); //will return Hola

5 - To use dynamic values with localized text, use the LocalizationManager.PARAMETER_DELIMITER between a key and call Getwith the respective dictionary.

//Example of a localized text with parameter
//playerPoints = You have @points@ points!
var pp = 10; 
var localizedPoints = LocalizationManager.Instance.Get("playerPoints", new Dictionary<string, string>() {{"points", pp.ToString()}});//will return You have 10 points!

LocalizationManager public overview

Properties

nametypedescription
CurrentLocaleLocaleThe current Locale being use to gather the translations.
onLocalizationChangedUnityEventCallback triggered when language is changed (usefull to change text/sprites that is already on screen)

Methods


LocalizationManager.ChangeReferenceFile

  • Description: Change the file to get the translations data.

  • Parameters:

nametypedescription
filePathstringPath to the file.

LocalizationManager.ResetLanguageToDeviceLanguage

  • Description: Resets the language to the system's default.

LocalizationManager.ChangeLanguage

  • Description: Changes the language.

  • Parameters :

nametypedescription
codestringISO language and country code. Previous registered in Locale

LocalizationManager.ChangeLanguage

  • Description: Changes the language.

  • Parameters :

nametypedescription
localeLocaleThe locale to be change

LocationManager.Exists

  • Description: Returns true if the key is present in the language dictionary.

  • Parameters :

nametypedescription
keystringKey to compare

LocationManager.Get

  • Description: Returns the localized string if it has the key. Otherwise will return DEFAULT_VALUE_MISSING_KEY;

  • Parameters :

nametypedescription
keystringKey to compare
replacesDictionary< string, string >Replaces texts that are between PARAMETER_DELIMITER character and replace with the value
  • Variants : --GetUpper: Return all the characters in uppercase; --GetLower: Return all the characters in lowercase; --GetFirstLetterUpper: Return with just the first letter uppercase and the rest lowercase; --TryGet: Returns true if there is a translation to that key and out the translation value;

LocationManager.FormatDate

  • Description: Format the date based on the locale culture info.

  • Parameters :

nametypedescription
dtDateTimeDate to be formated

LocationManager.FormatTime

  • Description: Format the time based on the locale culture info.

  • Parameters :

nametypedescription
dtDateTimeTime to be formated

LocationManager.FormatCurrency

  • Description: Format the currency based on the locale culture info.

  • Parameters :

nametypedescription
valueDoubleValue to be formated

LocationManager.FormatNumber

  • Description: Format the number based on the locale culture info.

  • Parameters :

nametypedescription
valueDoubleValue to be formated
decimalsintValue to be formated

LocationManager.FormatPercent

  • Description: Format the number percentage based on the locale culture info.

  • Parameters :

nametypedescription
valueDoubleValue to be formated
percentValueDoubleValue to be formated

LocationManager.ParseToFloat

  • Description: Parse the string into float based on the locale culture info.

  • Parameters :

nametypedescription
strstringValue to be parsed

LocationManager.ParseToInt

  • Description: Parse the string into int based on the locale culture info.

  • Parameters :

nametypedescription
strstringValue to be parsed

Future releases

  • Allow line jump in localized text
  • Allow csv files that are not local (internet)