Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Localize smart string (init localization)

Discussion in 'Localization Tools' started by bngames01, Mar 30, 2022.

  1. bngames01

    bngames01

    Joined:
    Apr 26, 2021
    Posts:
    28
    Hello,

    I'm trying to use a smart string with one parameter, but there is some issue to do, and I don't know what is the problem.

    I preloaded the table.
    I use a script, which has a variable:
    public LocalizeStringEvent rewardText;

    And in a function I try to set the variable:
    (rewardText.StringReference["rw"] as IntVariable).Value = reward;

    It worked, but now it doesn't. The error message is:
    ParsingErrors: The format string has 1 issue:
    '0xD': There are trailing operators in the selector
    In: "Your reward
    -{rw} "
    At: --------------^

    I try a way when I added to the Update String that text object and set it's text field, but also doesn't work.
    It doesn't work either when the Smart String checkbox is checked what you see in the image.
    What can be wrong?
    If tables are preloaded how can I use smart strings?
     

    Attached Files:

  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,232
    The smart string checkbox should be checked or it definitely won't work.
    What changed to stop it working? It looks correct.
    Does it work if you press the preview button on the smart string?
     
  3. bngames01

    bngames01

    Joined:
    Apr 26, 2021
    Posts:
    28
    Yes, I tried also if it was checked, but helped not.. I get that error message.
    No, in Preview and in Debug mode it gives that error which I mentioned.
    First when I installed localization plugin, I installed the samples, but I had another issue, which I could not solve, and I thought the sample localization and tables are the problem, so I removed them and all the localized plugin, but maybe there were some files which wasn't deleted. After that I reinstalled the localization plugin. It looked good, but I decided to delete a particular language with its table, I made it and there were no errors. But then I arrive to this section, from that I don't know why I get this error. Maybe I should completely remove the localization? But I would like to avoid to add again the translations in 4 languages, but if there are no solutions, then I have to do that.
    Do you have an idea what can be the solution? (I did not find how to remove language properly, after I removed the lang, the tables were kept)
     
  4. bngames01

    bngames01

    Joined:
    Apr 26, 2021
    Posts:
    28
    Oh, I think I found the cause...
    I just checked the lang asset file...
    m_Localized: "Your reward\n-{\rrw} "
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,232
    Oh yes, that would cause a problem. Had did that \r get in there?
     
  6. bngames01

    bngames01

    Joined:
    Apr 26, 2021
    Posts:
    28
    The main problem is:
    I have a dialog, which opens, if an event occurs.
    It has a script,
    and its ShowPanel method there is:
    public void ShowPanel(){
    Debug.Log("title: " + LocalizationSettings.StringDatabase.GetLocalizedString("UIText", "dialog_title"))
    }

    but when it runs, it gives error:
    No translation found for 'dialog_found' in UIText

    Actually I do not have any localization init, I only preloaded the table.
     
  7. bngames01

    bngames01

    Joined:
    Apr 26, 2021
    Posts:
    28
    I copied the translation from excel...
     
    karl_jones likes this.
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,232
    Your code says it's looking for the key dialog_title but the error says dialog_found. Looks like it's missing an entry with that name. Check it matches exactly, it's case sensitive.
     
  9. bngames01

    bngames01

    Joined:
    Apr 26, 2021
    Posts:
    28
    Thank you!
    Unfortunately, I copied the wrong message... it's not my copy day...entry name is in the table I checked it, so "dialog_title" is not found but it is in the table, maybe I should sleep a bit it is almost midnight
     
  10. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,232
    Try passing in the Key ID Instead of the name, if that works then there's something wrong with the name. Maybe it's got a \r in it as well?
     
  11. bngames01

    bngames01

    Joined:
    Apr 26, 2021
    Posts:
    28
    Hey,
    how do you mean, passing in the KEY ID instead of the name, can you write an example?
    No \r there.
    But the interesting things is, that if I make write the debug.log in the panel script's Start method, it gives also that No translation found.
     
  12. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,232
    This value
    Screenshot 2022-04-02 at 09.14.42.png

    Just use this value as an integer and see if it works. If it does then there's something wrong with the Key.

    E.g
    Code (csharp):
    1. LocalizationSettings.StringDatabase.GetLocalizedString("UIText", 98006364160))
     
    bngames01 likes this.
  13. bngames01

    bngames01

    Joined:
    Apr 26, 2021
    Posts:
    28
    Hey Karl,
    approx there are 5 keys that didn't work but it works with KEY ID. Strange, I exported the translations to a csv file, in fact there is no difference, expect this:
    "dialog_title
    ",3876967665664,"Settings",,,

    Maybe it should be in one line, but don't know if it matters. But in the Editor it in the input field it did not have a single space after the key.
    I deleted and added again these keys, now they work. Unbelievable. :)
    Huge thanks.
     
  14. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,232
    Ah great to hear it's working. That must have been very frustrating.
     
    bngames01 likes this.