Currently working on localization, just to share my implementation.
There are some advanced ways doing so as well, e.g. CSV support was added in 3.5.0. But this time I am still working with txt version.
We will need Unity3D installed and equipped with NGUI 2.7.0+
We will meet these two classes:
Localization is the manager class where we set up localization information, langauges, localized string resource.
We need to prepare our localized strings, format goes like this:
KEY = string
If you want to include leading space in your localized string, you can hack like this:
Attach the Localization manager to your game, it works as a singleton.
Create a GameObject, attach Localization script to that object.
Setup the locale resource file. In this case, I have 3 locales to work on.
It creates a "_Localization" object in your game and stay alive through out the whole game after initilization.
So, we don't need to define it everywhere in the game. (but you still can define it in your separated scene for testing purpose. Note that if a Localization instance is alive, a new one WILLNOT be initialized)
I have a
UILabel which displays "Start Game"
I want to translate "Start Game" into a different language.
Let's attach a script and set up the KEY
There are several ways to detect/ pick languages.
NGUI also provides a helper, NGUI LaguageSection. It helps you to create a drop down list for languages.
For iOS game, I detect language using this little script:
Current device language in iOS @ StackOverflow
After you figured out which locale to use, set current in Localization instance.
Build and run your game.
This also works on UISprite and UIButton.