Localization system

Overview

Localizing your game using NGUI is as simple as creating a CSV file with all your text and using the UILocalize component on your labels and sprites that you want to be localized.

NOTE: The CSV support was added in 3.5.0



The first step is creating the CSV file. You can use Google Docs, Excel, or any other application that's capable of creating excel style files.

The CSV file should contain two or more columns. The first column should contain keys that you will use in the Key field of the UILocalize component. Other columns should contain the actual localized values for those keys.

The first row should contain your language names -- English, French, Simplified Chinese, etc. When you want to switch a language in-game you can either use Localization.language = "English;" (or any other language defined in the first row), or just attach theLanguageSelection component to a drop-down list, turning it into a language selection list.

All other rows should contain the key in the first column and text values in all the subsequent columns. Just make sure that there are localized values present for all the given keys, or things may not work properly.

Once you're done, export the file in CSV file format as Localization.csv, and place it in the Resources folder. Unity 4 treats CSV files as Text files, but if you are still on Unity 3, you will need to rename that file to have a TXT extension or it won't be recognized.

To localize any label or sprite, attach UILocalize script to it and choose a key defined in the CSV file you created, and that's it! The label or sprite's value will be pulled from the localization file automatically, and when you switch languages, so will your label or sprite.

Pro-Tip #1

If you don't remember what your key was, just start typing in the UILocalize's "key" field. It will bring up a list of relevant entries for your convenience. Click on one of them to choose that value. Likewise you can click on the Preview options to have the localized object immediately assume that value.

Pro-Tip #2

If you are doing custom localization, you can still use the localization system. Use Localization.Get(key) anywhere in code to retrieve a localized value for the current language. To change the language -- Localization.language = "New Language";

Pro-Tip #3

Want even better localization tools? Have a look here -- http://www.tasharen.com/forum/index.php?topic=8324.0

Class Documentation

http://tasharen.com/ngui/docs/class_u_i_localize.html
http://tasharen.com/ngui/docs/class_localization.html

If you have a question regarding this component or would like me to clarify something, just post a reply here.

 

2014-12-23 : 在 实际 运行的 时候 最好关闭文本

posted @ 2014-12-23 20:01  灵魂重新  阅读(230)  评论(0)    收藏  举报