public static void AddUIDictionaryToDom(HtmlDom pageDom, CollectionSettings collectionSettings)
{
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>();
d.Add(collectionSettings.Language1Iso639Code, collectionSettings.Language1Name);
if (!String.IsNullOrEmpty(collectionSettings.Language2Iso639Code))
SafelyAddLanguage(d, collectionSettings.Language2Iso639Code,
collectionSettings.GetLanguage2Name(collectionSettings.Language2Iso639Code));
if (!String.IsNullOrEmpty(collectionSettings.Language3Iso639Code))
SafelyAddLanguage(d, collectionSettings.Language3Iso639Code,
collectionSettings.GetLanguage3Name(collectionSettings.Language3Iso639Code));
SafelyAddLanguage(d, "vernacularLang", collectionSettings.Language1Iso639Code);//use for making the vernacular the first tab
SafelyAddLanguage(d, "{V}", collectionSettings.Language1Name);
SafelyAddLanguage(d, "{N1}", collectionSettings.GetLanguage2Name(collectionSettings.Language2Iso639Code));
SafelyAddLanguage(d, "{N2}", collectionSettings.GetLanguage3Name(collectionSettings.Language3Iso639Code));
// 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);
MakePageLabelLocalizable(pageDom, 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;
}