/// <summary>
        /// Processes the response to the SupportedCultures command.
        /// </summary>
        /// <param name="supportedCulturesResponse">Command response data.</param>
        private void ProcessSupportedCulturesResponse(XElement supportedCulturesResponse)
        {
            //Expected response
            //<SupportedCultures>
            //  <Culture Key="..." Name="..."/>
            //  ...
            //</SupportedCultures>

            using (SupportedCultures.AcquireLock())
            {
                SupportedCultures.Clear();

                foreach (var languageElement in supportedCulturesResponse.Elements("Culture"))
                {
                    var key  = languageElement.Attribute("Key").Value;
                    var name = languageElement.Attribute("Name").Value;

                    SupportedCultures.Add(new LanguageElement(key, name));
                }

                if (SupportedCultures.Count > 0)
                {
                    SelectedLanguage = SupportedCultures[0];
                }
            }
        }
Example #2
0
        public SettingsViewModel(Settings settings)
        {
            _settings          = settings;
            _soundPing         = _settings.SoundPing;
            _supportedCultures = new ObservableCollection <CultureItem>();
            SupportedCultures.Add(new CultureItem(CultureInfo.InstalledUICulture, true));
            ResourceManager rm = new ResourceManager(typeof(Localization.Localization));

            CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
            foreach (CultureInfo culture in cultures)
            {
                try
                {
                    ResourceSet rs = rm.GetResourceSet(culture, true, false);
                    if (rs == null || culture.Equals(CultureInfo.InvariantCulture))
                    {
                        continue;
                    }
                    SupportedCultures.Add(new CultureItem(culture));
                }
                catch (CultureNotFoundException)
                {
                    Debug.WriteLine(culture + " is not available on the machine or is an invalid culture identifier.");
                }
            }
            CurrentCulture = SupportedCultures.Where(c => c.CultureInfo.Equals(_settings.Language.CultureInfo)).First();
        }
Example #3
0
        /// <summary>
        /// Initializer.
        /// </summary>
        static CultureResources()
        {
            if (!BFoundInstalledCultures)
            {
                foreach (var dir in Directory.GetDirectories(System.Windows.Forms.Application.StartupPath))
                {
                    try
                    {
                        var dirinfo  = new DirectoryInfo(dir);
                        var tCulture = CultureInfo.GetCultureInfo(dirinfo.Name);

                        if (dirinfo.GetFiles(
                                Path.GetFileNameWithoutExtension(System.Windows.Forms.Application.ExecutablePath) +
                                ".resources.dll").Length <= 0)
                        {
                            continue;
                        }

                        SupportedCulturesFullNames.Add(tCulture.NativeName);
                        SupportedCultures.Add(tCulture);
                    }
                    catch (ArgumentException)
                    {
                        // ignored
                    }
                }

                SupportedCulturesFullNames.Remove(
                    SupportedCulturesFullNames.Find(x => x == Properties.Settings.Default.LanguageName));
                SupportedCulturesFullNames.Insert(0, Properties.Settings.Default.LanguageName);

                BFoundInstalledCultures = true;
            }
        }
Example #4
0
        protected DefaultApiLocalization AddSupportedCulture(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            SupportedCultures ??= new List <CultureInfo>();

            SupportedCultures.Add(CultureInfo.GetCultureInfo(name));

            return(this);
        }