public static void AddUIDictionaryToDom(HtmlDom pageDom, CollectionSettings collectionSettings)
{
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) && !d.ContainsKey(collectionSettings.Language2Iso639Code))
d.Add(collectionSettings.Language2Iso639Code, collectionSettings.GetLanguage2Name(collectionSettings.Language2Iso639Code));
if (!String.IsNullOrEmpty(collectionSettings.Language3Iso639Code) && !d.ContainsKey(collectionSettings.Language3Iso639Code))
d.Add(collectionSettings.Language3Iso639Code, collectionSettings.GetLanguage3Name(collectionSettings.Language3Iso639Code));
d.Add("vernacularLang", collectionSettings.Language1Iso639Code);//use for making the vernacular the first tab
d.Add("{V}", collectionSettings.Language1Name);
d.Add("{N1}", collectionSettings.GetLanguage2Name(collectionSettings.Language2Iso639Code));
d.Add("{N2}", collectionSettings.GetLanguage3Name(collectionSettings.Language3Iso639Code));
AddLocalizedHintContentsToDictionary(pageDom, d, collectionSettings);
dictionaryScriptElement.InnerText = String.Format("function GetDictionary() {{ return {0};}}", JsonConvert.SerializeObject(d));
pageDom.Head.InsertAfter(dictionaryScriptElement, pageDom.Head.LastChild);
}