- Home /
How to use special symbols
Hello all, I'm translating my video game into three languages, spanish, english, and chinese, and I'm having trouble with chinese.
I have this text that displays the score when you die, so I copied and pasted this chinese translation from google translate into unity:
else if(PlayerPrefs.GetString("Language") == "Chinese") { deathscore.text = "你赚取了" + score + " 金"; eliminatedEnemies.text = "你杀了"+ enemiesDestroyed + " Hydra"; }
but when I run the game, white square appear where the chinese text is supposed to be. Could you help me please?
Answer by Bunny83 · Mar 25, 2019 at 02:14 PM
Are you sure you saved your code with UTF8 encoding? By default VisualStudio uses the Windows-1252 encoding (Western Europe) which is essentially the Latin1 character set as far as i remember. Just make sure you save your code as UTF8 to support the full unicode character set.
For I18n it's generally better to save the used texts into a seperate file. Commonly either some sort of csv, xml or json file which can be read by your game. Personally i would probably use json with my SimpleJSON framework. You can simply structure it like this:
{
"English" : {
"scoreText" : "You scored: {0}",
"eliminatedEnemy" : "You destroyed {0} {1}",
},
"Chinese" : {
"scoreText" : " ...{0} ...",
"eliminatedEnemy" : "... {0} {1}",
}
}
Now when parsing this text file (of course need to be saved with UTF8 as well) you can simply get the proper language sub object and the proper text like this:
JSONNode i18n;
JSONNode currentLang;
void Start()
{
i18n = Json.Parse(yourLanguageFileContent);
currentLang = i18n["Chinese"];
}
currentLang would now only contain the sub objects for the current selected language. You can use string.Format with the strings i've written in the example. So the "scoreText" requires one parameter which is the score. The "eliminatedEnemy" text requires two parameters, first enemiesDestroyed and second the enemy name ( assuming Hydra is the enemy name?! )
deathscore.text = string.Format(currentLang["scoreText"].Value, score);
eliminatedEnemies.text = string.Format(currentLang["eliminatedEnemy"].Value, enemiesDestroyed, "Hydra");
That way you have completely outsourced the internationalization part. Also when using string.Format you can more easily reuse the same text templates. Keep in mind that you can also simply store enemy names for different languages and look them up equally simple. You can even structure the json to have more sub categories. To translate to a new language, just send a copy of the english template to the translator.
ps: I just added comment support for my json parser. This is non standard but it doesn't interfer with any valid json. However that means when using "line comments" it can not be parsed with an ordinary json parser. With comments you can provide instructions for translators. For example:
{
"English" : {
// {0} = score
"scoreText" : "You scored: {0}",
// {0} = destroyed enemy count; {1} = enemy name
"eli$$anonymous$$atedEnemy" : "You destroyed {0} {1}",
},
Your answer
Follow this Question
Related Questions
Time.deltaTime using Hindi numbers? 1 Answer
Countdown Error 1 Answer
Hiding the part of a UI text behind a 3D object 1 Answer
Why the text and the UI code is can't applying 0 Answers
How to bold only the selected characters from a text? 3 Answers