Search Unity

Bug GetLocalizedString not making use of the Locale parameter

Discussion in 'Localization Tools' started by Robert_Luminous, Oct 12, 2022.

  1. Robert_Luminous

    Robert_Luminous

    Joined:
    May 21, 2019
    Posts:
    5
    Unless I am mistaken, passing a Locale into GetLocalizedStringAsync should force the string with the specified key to be returned using the specified locale. In my case it is always using the currently set locale (English for this example).

    The following section of code should demonstrate my issue:
    Code (CSharp):
    1.          // the localeString variable is a string set to "fr"
    2.         Locale locale = LocalizationSettings.AvailableLocales.GetLocale(localeString);          
    3.         Debug.Log($"{locale}");  // This is printing out: French (fr)
    4.  
    5.         returnString = LocalizationSettings.StringDatabase.GetLocalizedString(
    6.             "Example Table",
    7.             "Example Key",
    8.             new object[] { stepColliderReference.name, duration.ToString("0.0") ,
    9.             locale});
    10.            
    11.          // this returnString is set to the currently set langue (English)
    12.          return returnString;
    I have French set up to work with the given table and it produces the French value when I switch the langue. Any help would be greatly appreciated.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Can you make sure you are using the latest version 1.3.2?
     
  3. Robert_Luminous

    Robert_Luminous

    Joined:
    May 21, 2019
    Posts:
    5
    I can confirm I am on version Localization package 1.3.2
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    I see the problem! You are passing the locale in as a string argument

    Code (csharp):
    1. returnString = LocalizationSettings.StringDatabase.GetLocalizedString(
    2.     "Example Table",
    3.     "Example Key",
    4.     new object[] { stepColliderReference.name, duration.ToString("0.0") ,
    5.     locale});
    should be

    Code (csharp):
    1. returnString = LocalizationSettings.StringDatabase.GetLocalizedString(
    2.     "Example Table",
    3.     "Example Key",
    4.     new object[] { stepColliderReference.name, duration.ToString("0.0") },
    5.     locale);
    I moved the locale out of the object[] array so that it is the next argument.
     
    Robert_Luminous likes this.
  5. Robert_Luminous

    Robert_Luminous

    Joined:
    May 21, 2019
    Posts:
    5
    Oh wow silly me, thank you for catching that!
     
    karl_jones likes this.