/// ------------------------------------------------------------------------------------ /// <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> /// We are going to be used to choose a 'similar locale' for the specified /// locale. If this is a standard, built-in locale, disable the button and /// set its text to 'built-in'. If it's a custom locale, enable the button, /// and if the text used to be 'built-in' (that is, the previous target locale /// was built-in), change it to 'None'. /// </summary> /// <param name="localeName">Name of the locale.</param> /// <param name="rbroot">The rbroot.</param> /// ------------------------------------------------------------------------------------ public void SetupForSimilarLocale(string localeName, ILgIcuResourceBundle rbroot) { CheckDisposed(); if (IsCustomLocale(localeName, rbroot)) { // Since it's a custom locale the user is allowed to control it. // If it used to say "built in" change it to "none", otherwise, // they are changing from one custom locale to another, leave the // current selection alone. if (Text == m_res.GetString("kstidBuiltIn")) { Text = m_res.GetString("kstid_None"); } Enabled = true; } else { Text = m_res.GetString("kstidBuiltIn"); Enabled = false; } }
/// ------------------------------------------------------------------------------------ /// <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); } }
/// <summary> /// Make sure the root resource bundle is released. This is important to do before /// trying to update the resource files. /// </summary> public void ReleaseLangDefRb() { // ENHANCE (EberhardB): This should probably also be called from Dispose just to // be safe. if (m_rbLangDef != null) { // Allow this to be cleared to unlock memory mapping root.res Marshal.FinalReleaseComObject(m_rbLangDef); m_rbLangDef = null; IIcuCleanupManager icuMgr = IcuCleanupManagerClass.Create(); icuMgr.UnregisterCleanupCallback(this); } }