- Home /
Anyone know how to setup text localization with Button icons within the text?
We have localization within our game for PC.
We currently have something like...
"Press the [Crtl] button to crouch"
But we want to add controller support and cannot figure out how to replace the Ctrl with an icon representing a controller button.
Similar to: [https://i.ytimg.com/vi/utovhdJasRE/maxresdefault.jpg]
We could break up the sentence into peices, but the sentence structure would not be the same for each language so the icon would not necessarily be the same place.
Does any one know how this is usually handled, can I add a reference to an icon right in an XML string?
Answer by Hellium · Jul 30, 2018 at 06:29 PM
The simplest way, in my opinion, is to use TextMeshPro, the successor of the Text
component of Unity.
It's free since Unity 5.3.4, and downloadable from the Asset Store (Unity 2017.4 or older), or directly from the Package Manager in Unity 2018 and newer.
Then, create a SpriteSheet containing all your buttons and, in your XML file, just put the sprite
tag in your text, at the desired place, according to your translation. I believe you will need CDATA
to prevent the XML parser from interpreting the sprite
tag : https://msdn.microsoft.com/en-us/library/ms256076(v=vs.120).aspx
<jump>
<en><![CDATA[Press <sprite name="SpaceButton"> to jump]]</en>
<fr><![CDATA[Appuyez sur <sprite name="SpaceButton"> pour sauter]]</fr>
</jump>
How to create the Spritesheet
http://digitalnativestudios.com/textmeshpro/docs/sprites/
How to use the <sprite>
tag
http://digitalnativestudios.com/textmeshpro/docs/rich-text/#sprite
If the game supports that the user can setup the input the way he likes you may just put a placeholder in the localized string which you replace with the proper "sprite" based on the configured input when loading the text.
Answer by Bystander333 · Jul 30, 2018 at 06:01 PM
You could use a horizontal layout group - and split the text up.
Your answer
Follow this Question
Related Questions
gui text button dont work 1 Answer
GUI Text changes color to green / Possible 4.6.1 bug? 3 Answers
Displaying text from xml at runtime on different planes 0 Answers
How long is a string? 3 Answers
Text object can't be searched for with GameObject.Find 3 Answers