public IDictionary <string, string> LoadDictionary()
        {
            var language   = _languageProvider.GetLanguage();
            var dictionary = LoadDictionaryInternal(language);

            if (dictionary != null && dictionary.Any())
            {
                return(dictionary);
            }

            if (language == _settings.DefaultLanguage)
            {
                return(new Dictionary <string, string>());

                throw new DataException($"Unable to find storage for localization.");
            }

            dictionary = LoadDictionaryInternal(_settings.DefaultLanguage);
            if (dictionary != null && dictionary.Any())
            {
                return(dictionary);
            }

            throw new DataException($"Unable to find storage for localization.");
        }
Beispiel #2
0
        public string GetNative <TEnum>(TEnum localizationKey)
            where TEnum : struct, IComparable, IConvertible, IFormattable
        {
            var language = LanguageProvider.GetLanguage();
            var value    = Get(localizationKey, language);

            return(value);
        }
        private static string GetLangString(string key)
        {
            HttpRequest Request = HttpContext.Current.Request;
            /*默认语言是英文*/
            string lang = "zh-cn";

            ///*检查cookies是否有用户的语言设置*/
            //if (Request.Cookies["CoolCode_Lang"] != null)
            //    lang = Request.Cookies["CoolCode_Lang"].Value;
            ///*如果cookies中没有就取客户端的语言*/
            //else if (Request.UserLanguages.Length > 0)
            //{
            //    lang = Request.UserLanguages[0];
            //}
            /*加载语言,只在第一次使用时加载*/
            if (langProvider == null)
            {
                langProvider = new LanguageProvider();
            }
            return(langProvider.GetLanguage(lang, key));
        }