/// <summary> /// Initializes a new instance of the /// <see cref="T:SIL.FieldWorks.Common.Keyboarding.Linux.IcuLocale"/> class. /// </summary> public IcuLocale(string localeId) { Id = localeId; CountryCode = Icu.GetISO3Country(localeId); LanguageCode = Icu.GetISO3Language(localeId); LCID = Icu.GetLCID(localeId); }
private void InitLocales() { if (m_BadLocales != null) { return; } m_BadLocales = new List <IKeyboardErrorDescription>(); var configRegistry = XklConfigRegistry.Create(m_engine); var layouts = configRegistry.Layouts; var icuLocales = IcuLocalesByLanguageCountry; for (int iGroup = 0; iGroup < m_engine.GroupNames.Length; iGroup++) { // a group in a xkb keyboard is a keyboard layout. This can be used with // multiple languages - which language is ambigious. Here we just add all // of them. var groupName = m_engine.GroupNames[iGroup]; List <XklConfigRegistry.LayoutDescription> layoutList; if (!layouts.TryGetValue(groupName, out layoutList)) { // No language in layouts uses the groupName keyboard layout. m_BadLocales.Add(new KeyboardErrorDescription(groupName)); continue; } string unrecognizedLayout = null; for (int iLayout = 0; iLayout < layoutList.Count; iLayout++) { var layout = layoutList[iLayout]; string description; if (string.IsNullOrEmpty(layout.LayoutVariant)) { description = string.Format("{0} ({1})", layout.Language, layout.Country); } else { description = string.Format("{0} ({1}) - {2}", layout.Language, layout.Country, layout.LayoutVariant); } IcuLocale icuLocale; int lcid; if (icuLocales.TryGetValue(layout.Locale, out icuLocale)) { lcid = icuLocale.LCID; } else { lcid = Icu.GetLCID(layout.Locale); } if (lcid <= 0) { if (iLayout == 0) { unrecognizedLayout = groupName; } } else { // if we find the LCID for at least one layout, we don't report // the other failing variations of this layout as error. unrecognizedLayout = null; var keyboard = new XkbKeyboardDescription(lcid, description, this, iGroup); KeyboardController.Manager.RegisterKeyboard(lcid, keyboard); } } if (unrecognizedLayout != null) { m_BadLocales.Add(new KeyboardErrorDescription(unrecognizedLayout)); } } }