[api-minor] Move to Fluent for the localization (bug 1858715)

- For the generic viewer we use @fluent/dom and @fluent/bundle
- For the builtin pdf viewer in Firefox, we set a localization url
  and then we rely on document.l10n which is a DOMLocalization object.
This commit is contained in:
Calixte Denizet 2023-10-13 16:23:17 +02:00
parent 2a3090224f
commit 66982a2a11
155 changed files with 1311 additions and 28684 deletions

View file

@ -985,8 +985,7 @@ class TextAnnotationElement extends AnnotationElement {
"annotation-" +
this.data.name.toLowerCase() +
".svg";
image.alt = "[{{type}} Annotation]";
image.dataset.l10nId = "text_annotation_type";
image.dataset.l10nId = "pdfjs-text-annotation-type";
image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
if (!this.data.popupRef && this.hasPopupData) {
@ -2022,8 +2021,6 @@ class PopupAnnotationElement extends AnnotationElement {
}
class PopupElement {
#dateTimePromise = null;
#boundKeyDown = this.#keyDown.bind(this);
#boundHide = this.#hide.bind(this);
@ -2038,6 +2035,8 @@ class PopupElement {
#contentsObj = null;
#dateObj = null;
#elements = null;
#parent = null;
@ -2079,16 +2078,10 @@ class PopupElement {
this.#parentRect = parentRect;
this.#elements = elements;
const dateObject = PDFDateString.toDateObject(modificationDate);
if (dateObject) {
// The modification date is shown in the popup instead of the creation
// date if it is available and can be parsed correctly, which is
// consistent with other viewers such as Adobe Acrobat.
this.#dateTimePromise = parent.l10n.get("annotation_date_string", {
date: dateObject.toLocaleDateString(),
time: dateObject.toLocaleTimeString(),
});
}
// The modification date is shown in the popup instead of the creation
// date if it is available and can be parsed correctly, which is
// consistent with other viewers such as Adobe Acrobat.
this.#dateObj = PDFDateString.toDateObject(modificationDate);
this.trigger = elements.flatMap(e => e.getElementsToTriggerPopup());
// Attach the event listeners to the trigger element.
@ -2116,9 +2109,6 @@ class PopupElement {
if (this.#container.hidden) {
this.#show();
}
if (this.#dateTimePromise) {
await this.#dateTimePromise;
}
});
}
}
@ -2167,11 +2157,13 @@ class PopupElement {
({ dir: title.dir, str: title.textContent } = this.#titleObj);
popup.append(header);
if (this.#dateTimePromise) {
if (this.#dateObj) {
const modificationDate = document.createElement("span");
modificationDate.classList.add("popupDate");
this.#dateTimePromise.then(localized => {
modificationDate.textContent = localized;
modificationDate.dataset.l10nId = "pdfjs-annotation-date-string";
modificationDate.dataset.l10nArgs = JSON.stringify({
date: this.#dateObj.toLocaleDateString(),
time: this.#dateObj.toLocaleTimeString(),
});
header.append(modificationDate);
}
@ -3022,7 +3014,13 @@ class AnnotationLayer {
this.#setAnnotationCanvasMap();
await this.l10n.translate(layer);
if (
typeof PDFJSDev !== "undefined" &&
PDFJSDev.test("GENERIC && !TESTING") &&
this.l10n instanceof NullL10n
) {
await this.l10n.translate(layer);
}
}
/**