Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Check if "No translation found"

Discussion in 'Localization Tools' started by Fenikkel, Feb 17, 2023.

  1. Fenikkel

    Fenikkel

    Joined:
    Sep 24, 2019
    Posts:
    20
    Hi, I'm using Unity 2021.3.16f with the Localization package 1.3.2

    With the
    LocalizedString.IsEmpty
    I check if the LocalizedString is asigned or is left empty. But now I need to do a second check, that is: If the key have a translation for that Locale or is left empty.

    Actually I'm receiving No translation found for 'Key' in Table Collection Name

    I'm sure there is a clean way than check if the received string starts with "No translation found for"

    Thanks in advance! :D
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    Fenikkel likes this.
  3. Fenikkel

    Fenikkel

    Joined:
    Sep 24, 2019
    Posts:
    20
    Okey everyone, an easy solution is configure the parameters MissingTranslationState and NoTranslationFoundMessage in LocalizationSetting.

    That can be done, via the asset you created (LocalizationSettings (asset) -> String Database -> Missing Translation State & No Translation Found Message) or via script like this:

    Code (CSharp):
    1.         LocalizationSettings.StringDatabase.MissingTranslationState = MissingTranslationBehavior.PrintWarning;
    2.         LocalizationSettings.StringDatabase.NoTranslationFoundMessage = "No translation found for <b>'{key}'</b> in <b>{table.TableCollectionName}</b> in <b>{locale.name}</b> language";
    In my case, I disabled Show Missing Translation State in the MissingTranslationState for receive an empty string when there is no translation setted for the active locale.

    Now, @karl_jones , I still don't know how get all the translations (string) via just having a
    LocalizedString
    .

    I learned how to get the current Locale translation with this code:
    Code (CSharp):
    1.         // LocalizedString localizedString is a parameter of a method
    2.  
    3.         LocalizedStringTable localizedStringTable = new LocalizedStringTable(localizedString.TableReference);
    4.         StringTable stringTable = localizedStringTable.GetTable();
    5.         StringTableEntry stringTableEntry = stringTable.GetEntryFromReference(localizedString.TableEntryReference);
    6.         string value = stringTableEntry.Value; // or .LocalizedValue to get the string with the formatting applied
    Now I need to get all the non current Locale translations.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,845
    Oh yes good idea.
    You can set a LocaleOverride on the LocalizedStringTable,.this will let you get the value for a different locale.