예제 #1
0
        // Returns the CultureInfo representing the first language in the list that we can construct a CultureInfo for or null if
        // no such culture exists.
        private static CultureInfo GetBestFitCultureFromLanguageList(List <string> languages)
        {
            StringBuilder localeNameBuffer = new StringBuilder(Interop.Kernel32.LOCALE_NAME_MAX_LENGTH);

            for (int i = 0; i < languages.Count; i++)
            {
                if (CultureData.GetCultureData(languages[i], true) != null)
                {
                    return(new CultureInfo(languages[i]));
                }

                if (Interop.Kernel32.ResolveLocaleName(languages[i], localeNameBuffer, localeNameBuffer.MaxCapacity) != 0)
                {
                    string localeName = localeNameBuffer.ToString();

                    if (CultureData.GetCultureData(localeName, true) != null)
                    {
                        return(new CultureInfo(localeName));
                    }
                }
            }

            return(null);
        }
 /// <summary>
 /// Check whether CultureData exists for specified cultureName
 /// This API is used for WindowsRuntimeResourceManager in System.Runtime.WindowsRuntime
 /// </summary>
 public static bool IsValidCulture(string?cultureName)
 {
     return(CultureData.GetCultureData(cultureName, /* useUserOverride */ true) != null);
 }