Search Unity

Getting a localized string from each ("any") locale

Discussion in 'Localization Tools' started by plmx, Sep 10, 2021.

  1. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
    Hi.

    So, I'd like to list the languages available, each with its own (localized) name, for selection. A simple way to do this seems to be to create an entry named something like "languageName" which is localized. I know I can iterate over the available languages by using LocalizationSettings.AvailableLocales, but how do I retrieve a localized string for a specific (not the current) locale?

    (Or is there a better way of doing this?)

    Thanks!

    Philip
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    One of the samples shows how to display the English name combined with the localized name for that Locale. Is that what you want or do you want a localized name for the currently selected Locale?
    For that you would need to have a table with an entry for each Locale and then do a lookup.
    You can get a localized string for a specific Locale by either settings the LocaleOverride when using a LocalizedString or by passing in a Locale into GetLocalizedString.
     
    Wolfram likes this.
  3. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
    Yeah, I want to have localizers define the localized name and then do a lookup. I was looking exactly for the GetLocalizedString method that you mentioned. So, that solves the problem, thank you! (I somehow expected that there'd be a constructor for LocalizedString which takes a locale, but that might not be the best of ideas).

    Thanks also for reminding me about the samples, I completely forgot that they exist. May I humbly suggest to add a top-level entry to the localization documentation on https://docs.unity3d.com/Packages/com.unity.localization@1.0/manual/index.html about these samples? I for one would benefit from that reminder in the future...

    Philip
     
    karl_jones likes this.