Пример #1
0
        public static void SwitchToLang(string locale)
        {
            if (!AvailableLangDic.ContainsValue(locale))
            {
                locale = "zh-CN";
            }

            ResourceDictionary langRd;

            using (var s = new FileStream(Path.Combine(Domain.LangPath, $"{locale}.xaml"), FileMode.Open))
            {
                langRd = (ResourceDictionary)System.Windows.Markup.XamlReader.Load(s);
            }

            if (langRd == null)
            {
                return;
            }
            if (_i18nDic.MergedDictionaries.Count > 0)
            {
                // 如果已使用其他语言,先清空
                _i18nDic.MergedDictionaries.Clear();
            }

            _i18nDic.MergedDictionaries.Add(langRd);
            CurrentLocale = AvailableLangDic.First(k => k.Value == locale);
        }
Пример #2
0
        public static void SwitchToLang(string locale)
        {
            if (!AvailableLangDic.ContainsValue(locale))
            {
                locale = "en-US";
            }

            ResourceDictionary langRd;

            using (var s = new FileStream(Path.Combine(Domain.LangPath, $"{locale}.xaml"), FileMode.Open))
            {
                langRd = (ResourceDictionary)System.Windows.Markup.XamlReader.Load(s);
            }

            if (langRd == null)
            {
                return;
            }

            var current = I18NDic.MergedDictionaries[0];

            foreach (object key in langRd.Keys)
            {
                if (current.Contains(key))
                {
                    current[key] = langRd[key];
                }
            }

            CurrentLocale = AvailableLangDic.First(k => k.Value == locale);
        }