Example #1
0
        public static string ToString(LanguageMap map, string languageCode)
        {
            //Fast check
            if (map.ContainsKey(languageCode))
            {
                return(map[languageCode]);
            }

            //Search
            var parts = languageCode.ToLower().Split('-').ToList();

            while (parts.Count() > 0)
            {
                var match = map.Keys.FirstOrDefault(m => m.ToLower() == string.Join("-", parts));
                if (match != null)
                {
                    return(map[match]);
                }
                var closeMatch = map.Keys.FirstOrDefault(m => m.ToLower().Contains(string.Join("-", parts)));
                if (closeMatch != null)
                {
                    return(map[closeMatch]);
                }
                parts.Remove(parts.Last());
            }

            //Default
            return("");
        }
Example #2
0
 public string ToString(string languageCode)
 {
     return(LanguageMap.ToString(this, languageCode));
 }