Exemplo n.º 1
0
        /// <summary>
        /// Returns a valid culture name based on "name" parameter. If "name" is not valid, it returns the default culture "en-US"
        /// </summary>
        /// <param name="name" />Culture's name (e.g. en-US)</param>
        public static string GetImplementedCulture(string name)
        {
            Cultures = Cultures == null ? ValidCultures : Cultures;

            // make sure it's not null
            if (string.IsNullOrEmpty(name))
            {
                return(GetDefaultCulture); // return Default culture
            }
            // make sure it is a valid culture first
            if (ValidCultures.Where(c => c.Equals(name, StringComparison.Ordinal)).Count() == 0) // StringComparison.InvariantCultureIgnoreCase)).Count() == 0)
            {
                return(GetDefaultCulture);                                                       // return Default culture if it is invalid
            }
            // if it is implemented, accept it
            if (Cultures.Where(c => c.Equals(name, StringComparison.Ordinal)).Count() > 0)
            {
                return(name); // accept it
            }
            // Find a close match. For example, if you have "en-US" defined and the user requests "en-GB",
            // the function will return closes match that is "en-US" because at least the language is the same (ie English)
            var n = GetNeutralCulture(name);

            foreach (var c in Cultures)
            {
                if (c.StartsWith(n, StringComparison.Ordinal))
                {
                    return(c);
                }
            }
            // else
            // It is not implemented
            return(GetDefaultCulture); // return Default culture as no match found
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a valid culture name based on "name" parameter. If "name" is not valid, it returns the default culture "en-US"
        /// </summary>
        /// <param name="name">Culture's name (e.g. en-US)</param>
        public static string GetImplementedCulture(string name)
        {
            // Make sure it's not null
            if (string.IsNullOrEmpty(name))
            {
                return(GetDefaultCulture()); // return Default culture
            }
            // Make sure it is a valid culture first
            if (!ValidCultures.Any(c => c.Equals(name, StringComparison.InvariantCultureIgnoreCase)))
            {
                return(GetDefaultCulture()); // return Default culture if it is invalid
            }
            // If it is one of our implemented cultures, accept it
            if (ImplementedCultures.Any(c => c.Equals(name, StringComparison.InvariantCultureIgnoreCase)))
            {
                return(name); // accept it
            }
            // Find a close match. For example, if you have "en-US" defined and the user requests "en-GB",
            // the function will return closest match that is "en-US" because at least the language is the same (ie English)
            var n = GetNeutralCulture(name);

            foreach (var c in ImplementedCultures)
            {
                if (c.StartsWith(n))
                {
                    return(c);
                }
            }
            // else
            // It is not implemented
            return(GetDefaultCulture()); // return Default culture as no match found
        }