Search Unity

zh-'h'ans / zh-'h'ant locale code mismatch with locale codes within localization package ('H')

Discussion in 'Localization Tools' started by fouimet, Feb 27, 2021.

  1. fouimet

    fouimet

    Joined:
    Apr 13, 2018
    Posts:
    2
    Hi,

    I'm localizing my game in Chinese, traditional and simplified. In Unity (localization package 0.10-preview), I generated the following locales: zh-Hant and zh-Hans.

    When trying to test it on a test device, I found a problem where Chinese what not found in the locales, even though I switched my phone's language. My phone is not a "Chinese" phone so I can only change the language and not the CultureInfo.

    Tracing the problem, I found out that my phone returns "Invariant Culture info" which makes SystemLocaleSelector.cs branch out to using the system language to find the locale.

    Problem is, in SystemLanguageConverter.cs:
    Code (CSharp):
    1. case SystemLanguage.ChineseSimplified:  return "zh-hans";
    2.                 case SystemLanguage.ChineseTraditional: return "zh-hant";
    we get language codes with lowercase 'h' whereas the codes in the available locales are using 'H'. Although the created LocaleIdentifier is technically OK as Chinese, the matching fails in LocaleProvider.cs (line 55):
    Code (CSharp):
    1. public Locale GetLocale(LocaleIdentifier id)
    2.         {
    3.             foreach (var locale in Locales)
    4.             {
    5.                 if (locale.Identifier.Equals(id))
    6.                     return locale;
    7.             }
    8.             return null;
    9.         }
    If I hardcode a cultureInfo to (zh-HK), I can see that the code fails to find a direct match but because the culture info was properly created, the localization feature properly checks for the parent culture and properly finds 'zh-Hant'. (with capital 'H')

    Not sure if the proper solution is to change to a capital 'H' in SystemLanguageConverter. Any thoughts?

    Thanks!
     
    Last edited: Feb 28, 2021
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,299
    Ah this looks like a bug. Could you please file a bug report?
     
  3. fouimet

    fouimet

    Joined:
    Apr 13, 2018
    Posts:
    2
    Hi!

    I submitted a bug report (Case 1318190): https://fogbugz.unity3d.com/default.asp?1318190_22047un9e9dg9f0c

    Not sure if I was supposed to specifically tag the localization package somehow. I used the bug reporting tool in Unity.

    While creating the sample project, I found out that zh-Hant/Hans was duplicated between CultureInfo and SystemLanguage but with different capitalization. I find that using the 'hans/hant' locales in lowercase would be the best approach for now as the SystemLanguage fallback with lowercase codes would work to cover most cases whereas using Hant/Hans would work only for proper cultureInfo on phones but fail to support the CultureInfo.Invariant cases.

    ChineseLocales_CultureInfo.png ChineseLocales_SystemLanguage.png ChineseLocalesNotFound_DebugLogs.png
     
    karl_jones likes this.