Search Unity

TextMesh Pro TextMeshPro in conjunction with I2 Localization issue

Discussion in 'UGUI & TextMesh Pro' started by kabumere, Mar 22, 2018.

  1. kabumere

    kabumere

    Joined:
    Oct 2, 2016
    Posts:
    31
    I'm using the popular I2 Localization asset to help interchange my text for my game's supported languages. The default language I have selected is English. One issue I'm noticing is that if I try to change the text value of the TextMeshProUGUI object via code, the changes are not reflected and the default localized text remains.

    Random example to illustrate point:
    1) TextMeshProUGUI object has default english localization of "Hello there!"
    2) In a script, I do TextMeshProUGUI.text = "Greetings citizen!"
    3) I set TMP object to active so it's now visible.
    4) TMP object still says "Hello there!" even though the text field was set to "Greetings citizen!"

    I'm printing out the text field directly after assigning it and it is indeed being set correctly... I'm guessing this is an I2 Localization issue (maybe it ignores all changes to localized fields?), but wanted to see if anyone else has encountered this and if they have a workaround.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I haven't personally worked much with I2 Localization so hopefully some user who is way more familiar with it than I can provide assistance here.

    Otherwise, I would suggest contacting Frank at I2 Localization as he has always been very responsive to his users.

    I will of course make myself available to Frank should he require my assistance.
     
  3. Inter-Illusion

    Inter-Illusion

    Joined:
    Jan 5, 2014
    Posts:
    598
    Hi,
    Sorry for the delay in answering back. I don't normally check the UI forum so I missed this!

    That's the expected behavior. When you add a Localize component to a Label, you can no longer edit its text.
    Instead, the Localize component will use the Term you selected, and always show the label's text as the translation of that term.

    So, if you set a Localize component with a term ("MY_TERM", English: "Hello", Spanish: "Hola).
    Every time you enable the label or change language, the label's text will be set to "Hello" or "Hola" depending on the current language.

    If you want to change the text dynamically, you should either:
    - Disable the Localize component, which will allow you setting the text without it be modified.
    or
    - (recommended) Change the Localize term.
    http://inter-illusion.com/assets/I2LocalizationManual/ChangeLocalizeTerms.html
    For instance, if you just need a label that shows "Winner" or "Looser" (but also be translated to each language), then, create two terms "WINNER" and "LOOSER". Translate both terms.
    Then, instead of doing :
    Code (csharp):
    1. label.text = isWinner ? "Winner" : "Looser";
    do
    Code (csharp):
    1. label.GetComponent<Localize>().SetTerm(isWinner ? "WINNER" : "LOOSER")
    2.  
    That will change the term, which in turn will find the term's translation and set the label's text.

    Hope that helps,
    Frank