public static GetMetadata ( |
||
dom | ||
brandingNameOrFolderPath | string | Normally, the branding is just a name, which we look up in the official branding folder //but unit tests can instead provide a path to the folder. /// |
Результат | SIL.Windows.Forms.ClearShare.Metadata |
/// <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 }
/// <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) { // If it already has some of this information, just keep it. if (bookData.BookIsDerivative()) { 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 = BookCopyrightAndLicense.GetMetadata(dom).CopyrightNotice; if (String.IsNullOrEmpty(copyrightNotice) && collectionSettings.IsSourceCollection) { return; } bookData.Set("originalLicenseUrl", BookCopyrightAndLicense.GetLicenseUrl(dom), "*"); bookData.Set("originalCopyright", System.Web.HttpUtility.HtmlEncode(copyrightNotice), "*"); bookData.Set("originalLicenseNotes", dom.GetBookSetting("licenseNotes").GetFirstAlternative(), "*"); }