Now that we have a complete UI, let's configure the localization system and add a pop-up list to change our UI's language.
All our localized text strings must be contained in a .txt
file for each language. For the purpose of this book, we will have English and French, and we will need the English.txt
file and the French.txt
file.
Let's create them right now in the following manner:
Localization
.English.txt
.English.txt
file and rename it as French.txt
.Ok, now our localization files are ready to be used with the localization system.
We can now configure the localization system to work with our UI. We need to have the localization component attached to a GameObject in the scene:
English.txt
and French.txt
files in the languages array.The Starting Language is set to English, and we also have French available in the array.
The next step is to create a language selection box as shown in the following screenshot:
If we want to see what we're doing, we should first disable the Clipping of our Container by setting the Clipping
parameter in its UIPanel to None.
Once the Clipping is disabled, follow these steps:
CurrentDifficulty
.Language
.420
, -90
}.[AAFFFF]Language
.Language
and perform the following steps:English French
CurrentLanguage
.We can now reactivate Clipping in Container by setting the Clipping parameter in its UIPanel to Alpha Clip. The clipping Size has been saved.
That's it, our localization system is in place, and when the pop-up list changes value, the Language Selection.cs
script automatically changes the localization's Current Language value.
We are now ready to localize our first Label using the UILocalize component and a Key
that will define which string to use from our .txt
files. Perform the following steps:
Key
parameter by typing MainMenu
.English.txt
localization file and add the following line:MainMenu = [AAFFFF]Main Menu
French.txt
localization file and add the following line:MainMenu = [AAFFFF]Menu Principal
Save both the .txt
files and click on the play button. If you access options and change the language to French, our window's title changes from Main Menu to Menu Principal. That's because the UILocalize component updates the UILabel component it's attached to using the string present after the =
in our .txt
localization file. If you exit the play mode, the language will be saved and the UI will be initialized with the last selected language.
Now, we must add a UILocalize component with its specific Key
to every Label in the scene, then add a localization string for each of them in both of our .txt
files.
Don't be afraid; it isn't that long, and it will train you to use the Localization System:
Label
inside the search box.Now, all of our Label GameObjects have a UILocalize component attached to them. One by one, select them and set their Key
parameter based on their text set in the UILabel component.
You must ignore the Labels of Popup List; they don't need a UILocalize component since we checked their Localized Booleans. Simply add localization strings for their Options with the same names: Normal, Hard, English, and French.
When you're done with setting their Key
parameters, switch to our English.txt
file and add every key you need, plus =
followed by the corresponding localized text.
Now, copy all of these keys declarations and paste them in our French.txt
file and then replace the English words with French words or any other language you choose.
By the time you're finished, our entire UI will be localized!
3.141.38.121