/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the exemplar characters for the given ICU locale. /// </summary> /// <param name="icuLocale">Code for the ICU locale.</param> /// <returns> /// string containing all the exemplar characters (typically only lowercase /// word-forming characters) /// </returns> /// ------------------------------------------------------------------------------------ public string GetExemplarCharacters(string icuLocale) { ILgIcuResourceBundle rbExemplarCharacters = null; ILgIcuResourceBundle rbLangDef = null; try { rbLangDef = LgIcuResourceBundleClass.Create(); rbLangDef.Init(null, icuLocale); // if the name of the resource bundle doesn't match the LocaleAbbr // it loaded something else as a default (e.g. "en"). // in that case we don't want to use the resource bundle so release it. if (rbLangDef.Name != icuLocale) { return(string.Empty); } rbExemplarCharacters = rbLangDef.get_GetSubsection("ExemplarCharacters"); return(rbExemplarCharacters.String); } finally { if (rbExemplarCharacters != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(rbExemplarCharacters); } if (rbLangDef != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(rbLangDef); } } }
/// <summary> /// Determine whether the specified locale is a custom one the user is allowed to modify. /// </summary> /// <param name="localeId"></param> /// <returns></returns> public bool IsCustomLocale(string localeId) { ILgIcuResourceBundle rbroot = LgIcuResourceBundleClass.Create(); try { #if !__MonoCS__ rbroot.Init(null, "en"); #else // TODO-Linux: fix Mono bug rbroot.Init("", "en"); #endif ILgIcuResourceBundle rbCustom = rbroot.get_GetSubsection("Custom"); if (rbCustom != null) { ILgIcuResourceBundle rbCustomLocales = rbCustom.get_GetSubsection("LocalesAdded"); Marshal.ReleaseComObject(rbCustom); if (rbCustomLocales == null) { return(false); // Should never be. } while (rbCustomLocales.HasNext) { ILgIcuResourceBundle rbItem = rbCustomLocales.Next; if (rbItem.String == localeId) { Marshal.ReleaseComObject(rbItem); Marshal.ReleaseComObject(rbCustomLocales); return(true); } Marshal.ReleaseComObject(rbItem); } Marshal.ReleaseComObject(rbCustomLocales); } // Now, compare the locale againt all known locales -- it may not exist at all yet! // If not, it is considered custom. ILgIcuLocaleEnumerator locEnum = LgIcuLocaleEnumeratorClass.Create(); int cloc = locEnum.Count; for (int iloc = 0; iloc < cloc; iloc++) { if (localeId == locEnum.get_Name(iloc)) { Marshal.ReleaseComObject(locEnum); return(false); } } //Didn't find in either list...custom. Marshal.ReleaseComObject(locEnum); return(true); } finally { Marshal.ReleaseComObject(rbroot); } }
/// <summary> /// Determine whether the specified locale is a custom one the user is allowed to modify. /// </summary> /// <param name="localeId"></param> /// <param name="rbroot"></param> /// <returns></returns> public bool IsCustomLocale(string localeId, ILgIcuResourceBundle rbroot) { ILgIcuResourceBundle rbCustom = rbroot.get_GetSubsection("Custom"); if (rbCustom != null) { ILgIcuResourceBundle rbCustomLocales = rbCustom.get_GetSubsection("LocalesAdded"); System.Runtime.InteropServices.Marshal.ReleaseComObject(rbCustom); if (rbCustomLocales == null) { return(false); // Should never be. } while (rbCustomLocales.HasNext) { ILgIcuResourceBundle rbItem = rbCustomLocales.Next; if (rbItem.String == localeId) { System.Runtime.InteropServices.Marshal.ReleaseComObject(rbItem); System.Runtime.InteropServices.Marshal.ReleaseComObject(rbCustomLocales); return(true); } System.Runtime.InteropServices.Marshal.ReleaseComObject(rbItem); } System.Runtime.InteropServices.Marshal.ReleaseComObject(rbCustomLocales); } // Now, compare the locale againt all known locales -- it may not exist at all yet! // If not, it is considered custom. ILgIcuLocaleEnumerator locEnum = LgIcuLocaleEnumeratorClass.Create(); int cloc = locEnum.Count; for (int iloc = 0; iloc < cloc; iloc++) { if (localeId == locEnum.get_Name(iloc)) { System.Runtime.InteropServices.Marshal.ReleaseComObject(locEnum); return(false); } } //Didn't find in either list...custom. System.Runtime.InteropServices.Marshal.ReleaseComObject(locEnum); return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ private static bool RbItemWithLocaleIdOrNameExists(ref string localeId, ref string itemFullName, ILgIcuResourceBundle rb, string subsection) { string localeIdOrig = localeId; string itemNameOrig = itemFullName; if (localeId == null && itemFullName == null) throw new ArgumentException("Either localeId or itemName should be null, but not both"); ILgIcuResourceBundle rbLocales = null; try { rbLocales = rb.get_GetSubsection(subsection); if (rbLocales == null) return false; // Should never be. while (rbLocales.HasNext) { ILgIcuResourceBundle rbItem = null; try { rbItem = rbLocales.Next; if (localeIdOrig != null && rbItem.Key == localeId) itemFullName = rbItem.String; if (itemNameOrig != null && rbItem.String == itemNameOrig) localeId = rbItem.Key; // NOTE: it's okay to rename the fullName, if the key(localeId) is found. // but not okay to rename the Key if the fullName is found. if (localeIdOrig != null && localeIdOrig == rbItem.Key) { return true; } else if (itemNameOrig != null && itemNameOrig == rbItem.String) { return (localeIdOrig == null || localeIdOrig == rbItem.Key); } } finally { if (rbItem != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(rbItem); } } return false; } finally { if (rbLocales != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(rbLocales); } }