Search Unity

Currency Locale is Iconsistent Between LocalizedStringEvent + TMPro & Script

Discussion in 'Localization Tools' started by hasugg, Mar 5, 2021.

  1. hasugg

    hasugg

    Joined:
    Oct 14, 2017
    Posts:
    6
    Hello, I hope you're well. Found this weird issue today.

    Versions

    • macOS 11.2.1 (Intel)
    • Unity 2019.4.21f
    • Localization 0.10.0-preview
    Issue
    I have a String Table collection with an entry that uses Smart Format to output a currency value. When I wire this entry up to a TextMeshPro component and display the value, it uses the currency format per locale:

    • English(en) uses USD
    • French(fr) uses Euros
    • Arabic(ar) uses Saudi Riyals
    However if I access the exact same entry in code and log the output, I always get it in USD. Here's the code:

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.Localization;
    4. using UnityEngine.Localization.Tables;
    5.  
    6. public class LocalizedStringUser : MonoBehaviour
    7. {
    8.     [SerializeField] private LocalizedStringTable _localizedStringTable;
    9.     [SerializeField] private string _simpleStringKey;
    10.     [SerializeField] private string _interpolatedStringKey;
    11.     [SerializeField] private Values _interpolatedValues;
    12.  
    13.     private StringTable _currentStringTable;
    14.    
    15.     private IEnumerator Start()
    16.     {
    17.         var tableLoading = _localizedStringTable.GetTable();
    18.         yield return tableLoading;
    19.         _currentStringTable = tableLoading.Result;
    20.        
    21.         var simpleString = _currentStringTable[_simpleStringKey].LocalizedValue;
    22.  
    23.         Debug.Log($"Simple string: {simpleString}");
    24.        
    25.         var interpolatedString =
    26.             _currentStringTable[_interpolatedStringKey]
    27.                 .GetLocalizedString(_interpolatedValues);
    28.        
    29.         Debug.Log($"Interpolated string: {interpolatedString}");
    30.     }
    31. }
    Any help with this would be much appreciated.
     

    Attached Files:

  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    Ah yes GetLocalizedString for a table entry expects you to pass in the formatter.
    E.G
    Code (csharp):
    1. var interpolatedString = _currentStringTable[_interpolatedStringKey].GetLocalizedString(LocalizationSettings.SelectedLocale.Formatter, _interpolatedValues);
    I will file a bug so we can use the selected Locale if no value is passed.
     
  3. hasugg

    hasugg

    Joined:
    Oct 14, 2017
    Posts:
    6
    Ok wonderful. Thank you very much.
     
    karl_jones likes this.