views:

77

answers:

1

Why is CultureInfo.DisplayName in Sami all of a sudden? I use it to display a list of country names. Not a good idea perhaps but it worked until recently and I'm quite sure it was in Swedish (I guess it could have been English.)

MSDN says

This property represents the localized name from the .NET Framework version. For example, if the .NET Framework English version is installed, the property returns "English (United States)" for the en-US culture name. If the .NET Framework Spanish version is installed, regardless of the language that the system is set to display, the culture name is displayed in Spanish and the property for en-US returns "Ingles (Estados Unidos)".

But I'm quite sure I don't have Sami version of the framework installed.

My web-config has:

<globalization
        culture="sv-SE"
        uiCulture="sv-SE"/>

Addition: The code

        public static IEnumerable<KeyValuePair<string, string>> CountryList
    {
        get
        {
            Thread.CurrentThread.CurrentCulture =
                CultureInfo.CreateSpecificCulture("sv-SE");
            Thread.CurrentThread.CurrentUICulture = new
                CultureInfo("sv-SE"); 

            var cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
            /*Array.Sort(countries.Select(
                x => Regex.Match(x.DisplayName, "\\(([\\w- ]+)\\)").ToString()).ToArray(),
                countries);
            */

            SortedDictionary<string, CultureInfo> d = new SortedDictionary<string, CultureInfo>();
            foreach (CultureInfo cultureInfo in cultures)
            {
                string key = Regex.Match(cultureInfo.DisplayName, "\\(([\\w- ]+)\\)").ToString();
                if (!d.ContainsKey(key))
                    d.Add(key, cultureInfo);
            }

            var countries = d
                .Where(x => Regex.Match(x.Value.DisplayName, "\\([A-ZÅÄÖ]").Success)
                .Select(
                x => new KeyValuePair<string, string>(
                         Regex.Match(x.Value.Name, "-(\\w+)").Groups[1].ToString(),
                         Regex.Match(x.Value.DisplayName, "\\(([\\w- ]+)\\)").Groups[1].ToString()
                         ));
            return countries;
        }
    }
A: 

I assume your Window locale is set to smj-sv or something similar. The .NET Framework will then generate a culture as described in

Cultures Generated from Windows Locales

Normally, the values in your Web.config should overwrite the Windows (user's) locale setting, but maybe the values are no longer picked up from your Web.config. Did you check that the file is not corrupted and valid?

To see if it is a problem with your Web.config I would try setting the language programmatically by overriding the InitializeCulture method as decribed here:

How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization

0xA3
Thanks for your suggestion. I did as you said. Nothing new.
Martin