Exemplo n.º 1
0
        /// <summary>
        /// Load the localization from the user settings
        /// </summary>
        public static void LoadLocalization()
        {
            string cultureCode = Properties.Settings.Default.Localization_CultureCode;

            if (string.IsNullOrEmpty(cultureCode))
            {
                cultureCode = CultureInfo.CurrentCulture.Name;
            }

            LocalizationInfo info = LocalizationList.Where(x => x.Code == cultureCode).FirstOrDefault();

            if (info == null)
            {
                info = LocalizationList.First();
            }

            if (info.Code != Properties.Resources.Localization_DefaultCultureCode)
            {
                ChangeLocalization(info);
            }
            else
            {
                CurrentLocalization = info;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Change the localization
        /// </summary>
        /// <param name="info">LocalizationInfo</param>
        public static void ChangeLocalization(LocalizationInfo info)
        {
            // Set the current localization
            CurrentLocalization = info;

            // Remove dictionaries, which are no longer required
            if (_localizationResourceDictionary != null)
            {
                Application.Current.Resources.MergedDictionaries.Remove(_localizationResourceDictionary);
            }

            // Create/Initialize a new dictionary from the .xaml-file in the resource
            _localizationResourceDictionary = new ResourceDictionary {
                Source = new Uri(info.Path, UriKind.Relative)
            };

            // Add the new dictionary
            Application.Current.Resources.MergedDictionaries.Add(_localizationResourceDictionary);

            // Set the culture code
            Thread.CurrentThread.CurrentCulture = new CultureInfo(info.Code);
        }