コード例 #1
0
        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);
        }
コード例 #2
0
        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);

            // 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;
        }
コード例 #3
0
        private static DataSet GatherDataItemsFromCollectionSettings(CollectionSettings collectionSettings)
        {
            var data = new DataSet();

            data.WritingSystemAliases.Add("N1", collectionSettings.Language2Iso639Code);
            data.WritingSystemAliases.Add("N2", collectionSettings.Language3Iso639Code);

//            if (makeGeneric)
//            {
//                data.WritingSystemCodes.Add("V", collectionSettings.Language2Iso639Code);
//                    //This is not an error; we don't want to use the verncular when we're just previewing a book in a non-verncaulr collection
//                data.AddGenericLanguageString("iso639Code", collectionSettings.Language1Iso639Code, true);
//                    //review: maybe this should be, like 'xyz"
//                data.AddGenericLanguageString("nameOfLanguage", "(Your Language Name)", true);
//                data.AddGenericLanguageString("nameOfNationalLanguage1", "(Region Lang)", true);
//                data.AddGenericLanguageString("nameOfNationalLanguage2", "(National Lang)", true);
//                data.AddGenericLanguageString("country", "Your Country", true);
//                data.AddGenericLanguageString("province", "Your Province", true);
//                data.AddGenericLanguageString("district", "Your District", true);
//                data.AddGenericLanguageString("languageLocation", "(Language Location)", true);
//            }
//            else
            {
                data.WritingSystemAliases.Add("V", collectionSettings.Language1Iso639Code);
                data.AddLanguageString("nameOfLanguage", collectionSettings.Language1Name, "*", true);
                data.AddLanguageString("nameOfNationalLanguage1",
                                       collectionSettings.GetLanguage2Name(collectionSettings.Language2Iso639Code), "*", true);
                data.AddLanguageString("nameOfNationalLanguage2",
                                       collectionSettings.GetLanguage3Name(collectionSettings.Language2Iso639Code), "*", true);
                data.UpdateGenericLanguageString("iso639Code", collectionSettings.Language1Iso639Code, true);
                data.UpdateGenericLanguageString("country", collectionSettings.Country, true);
                data.UpdateGenericLanguageString("province", collectionSettings.Province, true);
                data.UpdateGenericLanguageString("district", collectionSettings.District, true);
                string location = "";
                if (!String.IsNullOrEmpty(collectionSettings.District))
                {
                    location += collectionSettings.District + @", ";
                }
                if (!String.IsNullOrEmpty(collectionSettings.Province))
                {
                    location += collectionSettings.Province + @", ";
                }

                if (!String.IsNullOrEmpty(collectionSettings.Country))
                {
                    location += collectionSettings.Country;
                }

                location = location.TrimEnd(new[] { ' ' }).TrimEnd(new[] { ',' });

                data.UpdateGenericLanguageString("languageLocation", location, true);
            }
            return(data);
        }
コード例 #4
0
 /// <summary>
 /// Give the string the user expects to see as the name of a specified language.
 /// This routine uses the user-specified name for the main project language.
 /// For the other two project languages, it explicitly uses the appropriate collection settings
 /// name for that language, though currently this gives the same result as the final default.
 /// This will find a fairly readable name for the languages Palaso knows about
 /// and fall back to the code itself if it can't find a name.
 /// Most names are not yet localized.
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 public string PrettyPrintLanguage(string code)
 {
     if (code == _collectionSettings.Language1Iso639Code && !string.IsNullOrWhiteSpace(_collectionSettings.Language1Name))
     {
         return(_collectionSettings.Language1Name);
     }
     if (code == _collectionSettings.Language2Iso639Code)
     {
         return(_collectionSettings.GetLanguage2Name(_collectionSettings.Language2Iso639Code));
     }
     if (code == _collectionSettings.Language3Iso639Code)
     {
         return(_collectionSettings.GetLanguage3Name(_collectionSettings.Language2Iso639Code));
     }
     return(_collectionSettings.GetLanguageName(code, _collectionSettings.Language2Iso639Code));
 }