private void ExportLDML(LgWritingSystem lgws, LdmlInFolderWritingSystemStore ldmlstore) { foreach (WritingSystemDefinition wsdT in ldmlstore.WritingSystemDefinitions) { // Don't bother changing an existing LDML file. if (wsdT.RFC4646 == lgws.RFC4646bis) { return; } } string sICU = lgws.ICULocale; string sLang; string sScript; string sCountry; string sVariant; Icu.UErrorCode err = Icu.UErrorCode.U_ZERO_ERROR; Icu.GetLanguageCode(sICU, out sLang, out err); if (sLang.Length > 3 && sLang.StartsWith("x")) { sLang = sLang.Insert(1, "-"); } Icu.GetScriptCode(sICU, out sScript, out err); Icu.GetCountryCode(sICU, out sCountry, out err); Icu.GetVariantCode(sICU, out sVariant, out err); if (sVariant == "IPA") { sVariant = "fonipa"; } Debug.Assert(err == Icu.UErrorCode.U_ZERO_ERROR); string sKeyboard; if (String.IsNullOrEmpty(lgws.KeymanKeyboard)) { sKeyboard = GetKeyboardName(lgws.Locale); } else { sKeyboard = lgws.KeymanKeyboard; } string sSortUsing = null; string sSortRules = null; if (lgws.CollationsOS.Count > 0) { try { ILgCollation coll = lgws.CollationsOS[0]; string sResName = coll.IcuResourceName; string sRules = coll.ICURules; int lcid = coll.WinLCID; if (!String.IsNullOrEmpty(sRules)) { sSortUsing = "CustomICU"; sSortRules = sRules; } else if (!String.IsNullOrEmpty(sResName)) { sSortUsing = "OtherLanguage"; sSortRules = sResName; } else if (lcid != 0) { sSortUsing = "OtherLanguage"; System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(lcid); sSortRules = ci.Name; } } catch { // This try-catch shouldn't be needed, but as LT-9545 points out, creating // the collation can crash for some non-repeatable reason. It's happened // twice on my machine, and once each for a couple of testers. } } WritingSystemDefinition wsd = new WritingSystemDefinition(sLang); wsd.Script = sScript; wsd.Region = sCountry; wsd.Variant = sVariant; wsd.LanguageName = lgws.Name.UserDefaultWritingSystem; wsd.Abbreviation = lgws.Abbr.UserDefaultWritingSystem; wsd.RightToLeftScript = lgws.RightToLeft; wsd.DefaultFontName = lgws.DefaultSerif; wsd.DefaultFontSize = 12; // pure guesswork - we need a stylesheet or a model change! wsd.Keyboard = sKeyboard; if (!String.IsNullOrEmpty(sSortUsing)) { wsd.SortUsing = sSortUsing; wsd.SortRules = sSortRules; } //wsd.NativeName = null; //wsd.SpellCheckingId = null; //wsd.StoreID = null; //wsd.VersionDescription = null; //wsd.VersionNumber = null; try { ldmlstore.SaveDefinition(wsd); } catch (Exception ex) { Debug.WriteLine(String.Format("Error writing LDML file: lgws.RFC={0}, wsd.RFC={1}; error: {2}", lgws.RFC4646bis, wsd.RFC4646, ex.Message)); } }