none
[UWP] CultureInfo.Name discrepancy between UWP and Destop RRS feed

  • Question

  • Hello,

    I've run into an issue where for some Win10 locales like Japanese the string returned by the UWP version of CultureInfo.Name is "ja" whereas the Desktop version returns "ja-jp" (running on the same machine at the same time so it's not like the culture is actually different).

    The MSDN for the UWP and Destop versions seem to agree "ja-jp" is the correct output.
    Is this a known issue or am I doing something wrong?

    Thanks,
    -yann


    Friday, July 15, 2016 9:05 PM

Answers

  • Finally got what's the problem here.

    From the documentation of ResolveLocaleName() function:

    [quote]

    Remarks

    The retrieved locale name indicates a specific locale, including language and country/region, even if the input language is neutral. For example, an input of "en" for English (United States) causes the function to retrieve "en-US".

    [/quote]


    Thursday, July 21, 2016 1:54 AM
    Answerer

All replies

  • That's because CultureInfo is a wrapper for the Regional Setting for the OS.

    Note that for Win10M where UWP Apps has to be able to run, you can only select the Country name in Language option, so a "language only culture name"(ja) is more valid choice to return than "language + country/region".


    To avoid the difference, if only "language" does matter to you, you can compare against CultureInfo.TwoLetterISOLanguageName property instead
    Monday, July 18, 2016 2:27 AM
    Answerer
  • Hi Cheong,

    Thanks for your reply. Unfortunately the two-letter language name is not enough for us as we need to differentiate between several culture's versions of the same language.

    I don't really follow the logic where being allowed to only select a country (e.g. JP for Japan) leads to CultureInfo only returning a language (ja for Japanese). How would that even work for countries like Switzerland where they have several languages? I may have misunderstood you there.

    What is strange is that the UWP version does return the language-country/region values for some of the locales. Why some and not others I have idea.

    Monday, July 18, 2016 5:56 PM
  • My bad, it should be "you can only select the Language name in Language option". Since only language is selected, it makes sense that it does not return the country name because in that case the Country is not known.

    Please take a look at the screenshot for WP8, you can see that there are "languages with country" listed too. I guess for these languages you can get the lang-country variant.

    Btw, if country really matters for your App, I think you add a mapping yourself serving all the LCID supported, and also assign default country to those "language only" LCIDs.

    Alternatively, seems create a new CultureInfo using CultureInfo.TextInfo.LCID could get the default country based culture with language can work too, but you'll need to test it on more cultures to make sure it work as planned.

    Tuesday, July 19, 2016 5:38 AM
    Answerer
  • I'm interested in the suggestion you make to "create a new CultureInfo using CultureInfo.TextInfo.LCID" to "get the default country based culture with language". The blog article you link to doesn't do that though, it creates a new CultureInfo object using "Ja-JP" as a starting point. Could you tell me more about that?

    Thanks again for your help.

    Tuesday, July 19, 2016 5:11 PM
  • That's based on assumption that LCID binded to TextInfo are linked to countries.

    You know, TextInfo is related to writing system specific behaviour, i.e.: code page and the sort. That kind of information is traditionally linked to a country.

    Btw, just tried a few others and find that maybe you can just use the following:

    System.Globalization.CultureInfo.GetCultureInfo("ja").TextInfo.CultureName

    Feeding "ja" there will return "ja-JP" and feeding "en" will return "en-US". Possibly what you want.

    Wednesday, July 20, 2016 1:43 AM
    Answerer
  • That piece of code returns "ja-JP" on Desktop but it still returns "ja" for UWP. Which gets us back to square one.
    Wednesday, July 20, 2016 4:36 PM
  • Finally got what's the problem here.

    From the documentation of ResolveLocaleName() function:

    [quote]

    Remarks

    The retrieved locale name indicates a specific locale, including language and country/region, even if the input language is neutral. For example, an input of "en" for English (United States) causes the function to retrieve "en-US".

    [/quote]


    Thursday, July 21, 2016 1:54 AM
    Answerer