private void InvokeWritingSystemWizard(ContextMenuStrip cmnuAddWs, out ILgWritingSystem lws, FdoCache cache, IHelpTopicProvider helpTopicProvider) { lws = null; using (new WaitCursor(this)) { using (WritingSystemWizard wiz = new WritingSystemWizard()) { wiz.Init(cache.LanguageWritingSystemFactoryAccessor, helpTopicProvider); if (wiz.ShowDialog() == DialogResult.OK) { // The engine from the wizard isn't the real one, so it doesn't have an id. IWritingSystem wsEngine = wiz.WritingSystem(); string strws = wsEngine.IcuLocale; ILgWritingSystemFactory wsf = cache.LanguageWritingSystemFactoryAccessor; wsEngine = wsf.get_Engine(strws); cache.ResetLanguageEncodings(); lws = LgWritingSystem.CreateFromDBObject(cache, wsEngine.WritingSystem); } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Finds or creates the writing system. /// </summary> /// <param name="cache">The cache.</param> /// <param name="icuLocale">The icu locale.</param> /// <returns>The writing system</returns> /// ------------------------------------------------------------------------------------ private LgWritingSystem FindOrCreateWs(FdoCache cache, string icuLocale) { // Look to see if the writing system already exists in the database foreach (LgWritingSystem ws in cache.LanguageEncodings) { if (LanguageDefinition.SameLocale(ws.ICULocale, icuLocale)) return ws; } // Create a new writing system based on the one noted in the XML file. // Load it in from the XML and save into the database. LanguageDefinitionFactory ldf = new LanguageDefinitionFactory(cache.LanguageWritingSystemFactoryAccessor, icuLocale); ldf.LanguageDefinition.SaveWritingSystem(icuLocale); cache.ResetLanguageEncodings(); // search again. It better be there now! foreach (LgWritingSystem ws in cache.LanguageEncodings) { if (LanguageDefinition.SameLocale(ws.ICULocale, icuLocale)) return ws; } Debug.Assert(false); return null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Obtain an interface to C# LgWritingSystem object for this locale in the database represented by this /// cache. If necessary create it from the XML and install it. /// </summary> /// <param name="cache"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ILgWritingSystem GetLgWritingSystem(FdoCache cache) { IWritingSystem wsEngine = EnsureRealWs(cache.LanguageWritingSystemFactoryAccessor); cache.ResetLanguageEncodings(); return (ILgWritingSystem)CmObject.CreateFromDBObject(cache, wsEngine.WritingSystem); }
/// <summary> /// Get the writing system code (int) for the given RFC4646 language code /// (string). /// </summary> public int GetWsFromRfcLang(string code, string sLdmlDir) { int ws; if (m_mapRFCtoWs.TryGetValue(code, out ws)) { return(ws); } string sWs = ConvertFromRFCtoICU(code); string sWsLower = sWs.ToLowerInvariant(); if (!m_mapIcuLCToWs.TryGetValue(sWsLower, out ws)) { // See if a compatible XML file exists defining this writing system. LanguageDefinition langDef; try { LanguageDefinitionFactory fact = new LanguageDefinitionFactory(); langDef = fact.InitializeFromXml( m_cache.LanguageWritingSystemFactoryAccessor, sWs) as LanguageDefinition; } catch { langDef = null; } ILgWritingSystem lgws; if (langDef != null) { // ICU locale case may differ - keep existing XML based value string sICU = langDef.IcuLocaleOriginal; Debug.Assert(sWsLower == sICU.ToLowerInvariant()); langDef.SaveWritingSystem(sICU, true); ws = m_cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(sICU); Debug.Assert(ws >= 1); lgws = LgWritingSystem.CreateFromDBObject(m_cache, ws); } else { WritingSystemDefinition wsd = null; if (!String.IsNullOrEmpty(sLdmlDir)) { LdmlInFolderWritingSystemStore ldmlstore = new LdmlInFolderWritingSystemStore(sLdmlDir); foreach (WritingSystemDefinition wsdT in ldmlstore.WritingSystemDefinitions) { if (wsdT.RFC4646 == code) { wsd = wsdT; break; } } } // This creates a new writing system for the given key. IWritingSystem wrsy = m_cache.LanguageWritingSystemFactoryAccessor.get_Engine(sWs); m_cache.ResetLanguageEncodings(); ws = wrsy.WritingSystem; Debug.Assert(ws >= 1); lgws = LgWritingSystem.CreateFromDBObject(m_cache, ws); lgws.ICULocale = sWs; if (wsd == null) { lgws.Abbr.UserDefaultWritingSystem = sWs; lgws.Name.UserDefaultWritingSystem = sWs; } else { lgws.Abbr.UserDefaultWritingSystem = wsd.Abbreviation; lgws.Name.UserDefaultWritingSystem = wsd.LanguageName; lgws.DefaultSerif = wsd.DefaultFontName; lgws.DefaultBodyFont = wsd.DefaultFontName; lgws.RightToLeft = wsd.RightToLeftScript; // TODO: collation, keyboard. } // Make sure XML file is written. See LT-8743. wrsy.SaveIfDirty(m_cache.DatabaseAccessor); } m_rgnewWrtSys.Add(lgws); m_cache.LangProject.AnalysisWssRC.Add(ws); m_cache.LangProject.CurAnalysisWssRS.Append(ws); if (m_fUpdateVernWss) { m_cache.LangProject.VernWssRC.Add(ws); m_cache.LangProject.CurVernWssRS.Append(ws); } m_mapIcuLCToWs.Add(sWsLower, ws); } m_mapRFCtoWs.Add(code, ws); return(ws); }