public void ParseLocaleName(ref string locale, // return case proper version out string lang, out string script, out string country, out string variant) { // use a single class/object for locale parsing - LocaleParser LocaleParser lp = new LocaleParser(locale); locale = lp.Locale; lang = lp.LangKey; script = lp.ScriptKey; country = lp.CountryKey; variant = lp.VariantKey; }
public void PopulateFromLanguageClass() { //Extracts the locale filename from a given path int icuName = m_inputFilename.LastIndexOf("\\"); string icuPortion = m_inputFilename.Substring(icuName+1); //Appears this maps the XML file to a LanguageDefinition class ///////////////// ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create(); LanguageDefinitionFactory langDefFactory = new LanguageDefinitionFactory(wsf, icuPortion); LanguageDefinition langDef = langDefFactory.InitializeFromXml(wsf, icuPortion) as LanguageDefinition; if (langDef == null) { throw new Exception("Unable to read and parse the input XML file " + m_inputFilename); } ///////////////// int i=0; int cpua = langDef.PuaDefinitionCount; // if we have PUA characters in the LD file make an array of PUACharacters. But be careful // to handle invalid definitions gracefully. if (langDef.PuaDefinitions != null && cpua != 0) { puaChars = new PUACharacter[cpua]; foreach (CharDef charDef in langDef.PuaDefinitions) { try { puaChars[i] = new PUACharacter(charDef); ++i; } catch { } } } if (i < cpua) { if (i == 0) { puaChars = null; } else { PUACharacter[] puaGoodChars = new PUACharacter[i]; for (int ic = 0; ic < i; ++ic) puaGoodChars[ic] = puaChars[ic]; puaChars = puaGoodChars; } if (LogFile.IsLogging()) LogFile.AddErrorLine("Warning, " + (cpua - i) + " out of " + cpua + " PUA character definitions are invalid."); } baseLocale = langDef.BaseLocale; newLocale = langDef.XmlWritingSystem.WritingSystem.IcuLocale; localeResources = langDef.LocaleResources; // Get the collation elements, whether from the CollationElements element directly, // or from the WritingSystem element. collationElements = langDef.CollationElements; if (collationElements == null) { IWritingSystem lws = langDef.WritingSystem; int ccoll = lws.CollationCount; if (ccoll > 0) collationElements = lws.get_Collation(0).IcuRules; } localeWinLCID = langDef.XmlWritingSystem.WritingSystem.Locale.ToString(); // make sure the newlocale has the proper case for each property: // lang, country and variant InstallLanguage.LocaleParser lp = new LocaleParser(newLocale); newLocale = lp.Locale; // Make sure the display names [Name, Country & Variant] have Unicode characters // greater than 7F converted to the \uxxxx format where xxxx is the unicode // hex value of the character. localeName = ConvertToUnicodeNotation(langDef.LocaleName); localeScript = ConvertToUnicodeNotation(langDef.LocaleScript); localeCountry = ConvertToUnicodeNotation(langDef.LocaleCountry); localeVariant = ConvertToUnicodeNotation(langDef.LocaleVariant); // Save the multilingual names of the writing system, together with the // ICU locale for each name. NameMultiUnicode rgName = langDef.XmlWritingSystem.Name; int cws = rgName.Count; // If we don't have a name, use the IcuLocale rather than going without a name. // Otherwise it won't register as a language in en.txt/res. if (cws == 0) { StringWithWs sw = new StringWithWs(langDef.XmlWritingSystem.WritingSystem.IcuLocale, "en"); rgName.Add(sw); cws = 1; } m_rgNames = new System.Collections.ArrayList(cws); for (int iws = 0; iws < cws; ++iws) { StringWithWs x = rgName[iws]; m_rgNames.Add(x); } // TODO - dlh // Once collationElements are handled, something will have to be checked there // as the current implementation assumes that it's in the valid format. wsf.Shutdown(); // This is (always) needed to balance creating the factory. }
public ICUInfo(string localeName, bool lang, bool script, bool country, bool variant) { m_LocaleInfo = new LocaleParser(localeName); m_LanguageExists = lang; m_ScriptExists = script; m_CountryExists = country; m_VariantExists = variant; }