Search Unity

Question iOS: Localization uses English always, regardless of system language

Discussion in 'Localization Tools' started by Peter77, Oct 27, 2021.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Unity 2019.4.20f1, Localization 1.0.4, Addressables 1.19.9

    Running my game on iOS, where the system language is set to German, causes the Localization system to detect it as English. It does work on Android though. Where could I start looking to figure out why that is?

    Running this code:
    Code (CSharp):
    1. yield return LocalizationSettings.InitializationOperation;
    2. yield return LocalizationSettings.StringDatabase.PreloadOperation;
    3. yield return LocalizationSettings.SelectedLocaleAsync;
    4.        
    5. Debug.LogFormat("Application: {0}", Application.systemLanguage);
    6. Debug.LogFormat("Localization: {0}", LocalizationSettings.SelectedLocale.Identifier.Code);
    Outputs on iOS:
    Code (CSharp):
    1. Application: German
    2. Localization: en
    Here is my Localization setup:
    upload_2021-10-27_7-40-15.png
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,276
    We only currently detect the system language, not the application preferred language. We have a bug for this that just came in yesterday so we will be looking at supporting preferred language for iOS.
     
    Peter77 likes this.
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Thank you for the reply.

    How can I make my iOS app select the language that's selected in iOS, rather than English? Unfortunately, I can't wait for a Localization package update, I need to find a workaround as soon as possible.

    In the iOS language settings, it uses German (Deutsch) for both, system and preferred language, yet the Localization system still selects English:

    upload_2021-10-27_9-53-58.png
     
    Last edited: Oct 27, 2021
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,276
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Thank you for the reply.

    What's weird is that
    UnityEngine.Application.systemLanguage
    returns the correct language, but it seems the Localization system doesn't pick it up.

    On the other hand, what I found in the Localization code is that the
    SystemLocaleSelector
    first tries to get the locale from
    CultureInfo.CurrentUICulture
    and only attempts to use
    UnityEngine.Application.systemLanguage
    in case the CurrentUICulture locale wasn't found.

    Perhaps
    CultureInfo.CurrentUICulture
    returns English on iOS always, regardless of the actual system or preferred language setting.
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    FYI: The CultureInfo seems incorrect on Android when using Hindi as system language. The Hindi two-letter-iso would be
    hi
    , but it returns
    iv
    . Is this a known Unity/Mono bug?

    Code (CSharp):
    1. CurrentCulture.EnglishName: Invariant Language (Invariant Country)
    2. CurrentCulture.TwoLetterISO: iv
    3. CurrentCulture.ThreeLetterISO: IVL
    4.  
    5. CurrentUICulture.EnglishName: Invariant Language (Invariant Country)
    6. CurrentUICulture.TwoLetterISO: iv
    7. CurrentUICulture.ThreeLetterISO: IVL
    8.  
    9. Application.systemLanguage: Unknown
     
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,276
    Peter77 likes this.
  8. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Thank you for the quick reply, much appreciated!
     
    karl_jones likes this.
  9. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    I'm giving it another shot:
    (Case 1376786) CultureInfo returns "Invariant Language" instead of the actual language
     
    karl_jones likes this.
  10. Pudija

    Pudija

    Joined:
    Nov 16, 2021
    Posts:
    1
    Was this bug fixed? I have a similar issue with WebGL build.
     
    ShenDh likes this.
  11. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,276
  12. nopropsneeded

    nopropsneeded

    Joined:
    Jun 27, 2019
    Posts:
    20
    I am experiencing the same issue on macOS Ventura 13.2.1, using Unity 2021.3.27f1 Personal.
    I want the display language to be Japanese when the system language is Japanese, and English otherwise.
    However, even when Application.systemLanguage is Japanese, LocalizationSettings.SelectedLocale.Identifier always remains 'en'.
    I haven't yet tested on platforms other than macOS.

    Is there any way to ensure the locale matches the system language correctly?

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Localization.Settings;
    3. using TMPro;
    4. using UnityEngine.ResourceManagement.AsyncOperations;
    5. using UnityEngine.Localization;
    6.  
    7. public class VersionAndLocalTextUI : MonoBehaviour
    8. {
    9.     [SerializeField]
    10.     TextMeshProUGUI m_label;
    11.  
    12.     void Start()
    13.     {
    14.         LocalizationSettings.SelectedLocaleAsync.Completed += OnLocaleSelectionCompleted;
    15.     }
    16.  
    17.     void OnLocaleSelectionCompleted(AsyncOperationHandle<Locale> handle)
    18.     {
    19.         UpdateVersionAndLocaleText();
    20.     }
    21.  
    22.     void UpdateVersionAndLocaleText()
    23.     {
    24.         string versionString = Application.version;
    25.         SystemLanguage systemLang = Application.systemLanguage;
    26.         var localeIdentifier = LocalizationSettings.SelectedLocale.Identifier;
    27.         m_label.text = $"{versionString}\nsystemLanguage:{systemLang}\nselectedLocale:{localeIdentifier.Code}";
    28.     }
    29. }
    30.  
    スクリーンショット 2023-07-10 18.15.28.png
     
  13. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,276
    What version of the package are you using? Try updating to 1.4.4. If it's not visible in the package manager you can edit the manifest.json file in the projects Packages folder.
     
  14. nopropsneeded

    nopropsneeded

    Joined:
    Jun 27, 2019
    Posts:
    20
    Thank you for your response.
    I updated the Localization to version 1.4.4 by modifying the manifest.json file. I created a macOS build and ran it, but the result was the same.
    Even though Application.systemLanguage is Japanese, LocalizationSettings.SelectedLocale.Identifier is still 'en'.

    スクリーンショット 2023-07-10 19.56.49.png
     
  15. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,276
    nopropsneeded likes this.
  16. nopropsneeded

    nopropsneeded

    Joined:
    Jun 27, 2019
    Posts:
    20
    karl_jones likes this.