Esempio n. 1
0
        /// <summary>
        ///   Get the language supported by the regional website based on culture
        /// </summary>
        /// <param name="cultureName"> The culture to lookup </param>
        /// <returns> Language of the culture specified is returned if available and supported by the website, otherwise the default language for the regional site is used. </returns>
        public string GetSupportedLocale(string cultureName)
        {
            if (string.IsNullOrEmpty(cultureName))
            {
                cultureName = CultureInfo.CurrentCulture.Name;
            }
            // try to find the exact culture
            string foundCulture =
                SupportedLocales.FirstOrDefault(sc => string.Equals(cultureName, sc, StringComparison.OrdinalIgnoreCase));

            if (foundCulture == null)
            {
                // if not available, try to find a culture with the same language
                foundCulture =
                    SupportedLocales.FirstOrDefault(
                        sc =>
                        string.Equals(cultureName.Substring(0, 2), sc.Substring(0, 2),
                                      StringComparison.OrdinalIgnoreCase));
                if (foundCulture == null)
                {
                    return(SupportedLocales[0]); // if not available get the site's default language
                }
            }
            return(foundCulture);
        }
Esempio n. 2
0
        public string ResolveLocale(string localeCode)
        {
            var result = SupportedLocales.FirstOrDefault(l => l.Key.Contains(localeCode)).Key;

            if (string.IsNullOrEmpty(result))
            {
                result = DefaultLocale;
            }

            return(result);
        }