public static void AddUIDictionaryToDom(HtmlDom pageDom, BookData bookData) { CheckDynamicStrings(); // add dictionary script to the page XmlElement dictionaryScriptElement = pageDom.RawDom.SelectSingleNode("//script[@id='ui-dictionary']") as XmlElement; if (dictionaryScriptElement != null) { dictionaryScriptElement.ParentNode.RemoveChild(dictionaryScriptElement); } dictionaryScriptElement = pageDom.RawDom.CreateElement("script"); dictionaryScriptElement.SetAttribute("type", "text/javascript"); dictionaryScriptElement.SetAttribute("id", "ui-dictionary"); var d = new Dictionary <string, string>(); foreach (var lang in bookData.GetAllBookLanguages()) { SafelyAddLanguage(d, lang.Iso639Code, lang.GetNameInLanguage(lang.Iso639Code)); } SafelyAddLanguage(d, "vernacularLang", bookData.Language1.Iso639Code); //use for making the vernacular the first tab SafelyAddLanguage(d, "{V}", bookData.Language1.Name); SafelyAddLanguage(d, "{N1}", bookData.MetadataLanguage1.GetNameInLanguage(bookData.MetadataLanguage1IsoCode)); if (!string.IsNullOrEmpty(bookData.Language3IsoCode)) { SafelyAddLanguage(d, "{N2}", bookData.MetadataLanguage2.GetNameInLanguage(bookData.MetadataLanguage2IsoCode)); } // TODO: Eventually we need to look through all .bloom-translationGroup elements on the current page to determine // whether there is text in a language not yet added to the dictionary. // For now, we just add a few we know we need AddSomeCommonNationalLanguages(d); // Hard-coded localizations for 2.0 AddHtmlUiStrings(d); // Do this last, on the off-chance that the page contains a localizable string that matches // a language code. AddLanguagesUsedInPage(pageDom.RawDom, d); dictionaryScriptElement.InnerText = String.Format("function GetInlineDictionary() {{ return {0};}}", JsonConvert.SerializeObject(d)); // add i18n initialization script to the page //AddLocalizationTriggerToDom(pageDom); pageDom.Head.InsertAfter(dictionaryScriptElement, pageDom.Head.LastChild); _collectDynamicStrings = false; }