GetMultiTextVariableOrEmpty() public method

public GetMultiTextVariableOrEmpty ( string key ) : SIL.Text.MultiTextBase
key string
return SIL.Text.MultiTextBase
Example #1
0
        /// <summary>
        /// Copy the copyright & license info to the originalCopyrightAndLicense,
        /// then remove the copyright so the translator can put in their own if they
        /// want. We retain the license, but the translator is allowed to change that.
        /// If the source is already a translation (already has original copyright or license)
        /// we keep them unchanged.
        /// </summary>
        public static void SetOriginalCopyrightAndLicense(HtmlDom dom, BookData bookData, CollectionSettings collectionSettings)
        {
            // At least one of these should exist if the source was a derivative, since we don't allow a
            // book to have no license, nor to be uploaded without copyright...unless of course it was derived
            // before 3.9, when we started doing this. In that case the best we can do is record the earliest
            // information we have for this and later adaptations.
            if (bookData.GetMultiTextVariableOrEmpty("originalLicenseUrl").Count > 0 ||
                bookData.GetMultiTextVariableOrEmpty("originalLicenseNotes").Count > 0 ||
                bookData.GetMultiTextVariableOrEmpty("originalCopyright").Count > 0)
            {
                return;                 //leave the original there.
            }
            // If there's no copyright information in a source-collection book, we're presumably making
            // a new original book, and shouldn't try to record any original copyright and license information.
            // This is somewhat redundant with the check in BookStarter.SetupNewDocumentContents(), the one
            // non-unit-test current caller of this method, that doesn't call this at all if the source is
            // a template book. I was trying for a minimal reasonable change for BL-5131, and therefore
            // put in this extra check, since previously this method was simply NEVER called in a source
            // collection.
            var copyrightNotice = GetMetadata(dom).CopyrightNotice;

            if (string.IsNullOrEmpty(copyrightNotice) && collectionSettings.IsSourceCollection)
            {
                return;
            }
            bookData.Set("originalLicenseUrl", GetLicenseUrl(dom), "*");
            bookData.Set("originalCopyright", System.Web.HttpUtility.HtmlEncode(copyrightNotice), "*");
            bookData.Set("originalLicenseNotes", dom.GetBookSetting("licenseNotes").GetFirstAlternative(), "*");
            bookData.RemoveAllForms("copyright");              // RemoveAllForms does modify the dom
        }
Example #2
0
        /// <summary>
        /// Copy the copyright & license info to the originalCopyrightAndLicense,
        /// then remove the copyright so the translator can put in their own if they
        /// want. We retain the license, but the translator is allowed to change that.
        /// </summary>
        public static void SetOriginalCopyrightAndLicense(HtmlDom dom, BookData bookData, CollectionSettings collectionSettings)
        {
            if (bookData.GetMultiTextVariableOrEmpty("originalCopyrightAndLicense").Count > 0)
            {
                return;                 //leave the original there.
            }
            var    metadata = BookCopyrightAndLicense.GetMetadata(dom);
            string idOfLanguageUsed;
            var    languagePriorityIds = collectionSettings.LicenseDescriptionLanguagePriorities;

            //TODO HOW DO I GET THESE IN THE NATIONAL LANGUAGE INSTEAD OF THE UI LANGUAGE?

            var    license = metadata.License.GetMinimalFormForCredits(languagePriorityIds, out idOfLanguageUsed);
            string originalLicenseSentence;
            var    preferredLanguageIds = new[] { collectionSettings.Language2Iso639Code, LocalizationManager.UILanguageId, "en" };

            if (metadata.License is CustomLicense)
            {
                // I can imagine being more fancy... something like "Licensed under custom license:", and get localizations
                // for that... but sheesh, these are even now very rare in Bloom-land and should become more rare.
                // So for now, let's just print the custom license contents.
                originalLicenseSentence = license;
            }
            else
            {
                var licenseSentenceTemplate = LocalizationManager.GetString("EditTab.FrontMatter.OriginalLicenseSentence",
                                                                            "Licensed under {0}.",
                                                                            "On the Credits page of a book being translated, Bloom puts texts like 'Licensed under CC-BY', so that we have a record of what the license was for the original book. Put {0} in the translation, where the license should go in the sentence.",
                                                                            preferredLanguageIds, out idOfLanguageUsed);
                originalLicenseSentence = string.IsNullOrWhiteSpace(license) ? "" : string.Format(licenseSentenceTemplate, license);
                originalLicenseSentence = originalLicenseSentence.Replace("..", ".");                  // in case had notes which also had a period.
            }

            Console.WriteLine(originalLicenseSentence);
            var copyrightNotice = "";

            if (string.IsNullOrWhiteSpace(metadata.CopyrightNotice))
            {
                var noCopyrightSentence = LocalizationManager.GetString("EditTab.FrontMatter.OriginalHadNoCopyrightSentence",
                                                                        "Adapted from original without a copyright notice.",
                                                                        "On the Credits page of a book being translated, Bloom shows this if the original book did not have a copyright notice.",
                                                                        preferredLanguageIds, out idOfLanguageUsed);

                copyrightNotice = noCopyrightSentence + " " + originalLicenseSentence;
            }
            else
            {
                var originalCopyrightSentence = LocalizationManager.GetString("EditTab.FrontMatter.OriginalCopyrightSentence",
                                                                              "Adapted from original, {0}.",
                                                                              "On the Credits page of a book being translated, Bloom shows the original copyright. Put {0} in the translation where the copyright notice should go. For example in English, 'Adapted from original, {0}.' comes out like 'Adapted from original, Copyright 2011 SIL'.",
                                                                              preferredLanguageIds, out idOfLanguageUsed);
                copyrightNotice = String.Format(originalCopyrightSentence, metadata.CopyrightNotice.Trim()) + " " + originalLicenseSentence;
            }
            Console.WriteLine(copyrightNotice);
            bookData.Set("originalCopyrightAndLicense", copyrightNotice, "*");
            bookData.RemoveAllForms("copyright");              // RemoveAllForms does modify the dom
        }
Example #3
0
 public void Set_CalledTwiceWithDIfferentLangs_HasBoth()
 {
     var htmlDom = new HtmlDom();
     var data = new BookData(htmlDom, new CollectionSettings(), null);
     data.Set("1", "one", "en");
     data.Set("1", "uno", "es");
     Assert.AreEqual(2,data.GetMultiTextVariableOrEmpty("1").Forms.Count());
 }