Search Unity

Question How to check the current local

Discussion in 'Localization Tools' started by bz_apps, Nov 11, 2022.

  1. bz_apps

    bz_apps

    Joined:
    Aug 19, 2014
    Posts:
    72
    Hi what is the best way to check the locale?

    Im currently using:

    Code (CSharp):
    1. var locale = LocalizationSettings.SelectedLocale.Identidier.Code;
    But this requires a string comparison and potential typos.

    Is it better to use the Application.systemLanguage? With this I can compare against preset 'SystemLanguage'.

    Does the localization system use the Application systemLanguage as its default unless explicitly set?

    Thanks,

    Adam
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
  3. bz_apps

    bz_apps

    Joined:
    Aug 19, 2014
    Posts:
    72
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    The string en is the simplest however it could also be a subset such as en-US. You can also check the application language enum.
    E.g

    Locale.Identifier == SystemLanguage.English

    or

    Locale.Identifier == "en"

    https://docs.unity3d.com/Packages/c...nityEngine.Localization.LocaleIdentifier.html
     
    Last edited: Nov 13, 2022
    jGate99 and bz_apps like this.
  5. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,945
    Hi @karl_jones
    Sorry for hijacking this thread, I have a similar question

    I'm using localization package for storing "app" localization, but i I also have app content (assuming in millions) that will have localization.

    So I wanted to ask which value should I use from culture info so i can easily match device identifier.
    For example if i save "en" for english, so how do i compare this value assuming there could be "en-us" (where it will fail)

    So are you saying that Locale.Identifier will always be showing "en" rather than "en-US" or "en-uk"?

    I noticed "standard" value
    Code (CSharp):
    1. CultureInfo.TwoLetterISOLanguageName
    provides standard value , is there alternate in Locale
    Thanks
     
    Last edited: Nov 26, 2022
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    jGate99 likes this.
  7. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,945
    Yes, Idea is to match backend stored (2 letter language code) with device language code and then serve backend content based on 2 letter language code.
    Thanks for the link, really appreciate
     
    karl_jones likes this.