Skip to content

Commit

Permalink
Utilize Fluent to format dates in the AnnotationLayer
Browse files Browse the repository at this point in the history
The `AnnotationLayer` may not display correctly formatted data in PopupAnnotations, especially in the GENERIC viewer, since it's using native methods[1] that depend on the *browser* locale instead of the viewer locale as intended.
With Fluent we're able to improve things since it's got built-in support for formatting dates. Not only does this simplify the JavaScript code slightly, but it also gives the localizer more fine-grained control of the desired output.

Please find additional information here:
 - https://projectfluent.org/fluent/guide/builtins.html
 - https://projectfluent.org/fluent/guide/functions.html

---

[1] `toLocaleDateString`, and `toLocaleTimeString`.
  • Loading branch information
Snuffleupagus committed Aug 23, 2024
1 parent b11b891 commit f40880c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
5 changes: 2 additions & 3 deletions l10n/en-US/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,8 @@ pdfjs-rendering-error = An error occurred while rendering the page.
## Annotations

# Variables:
# $date (Date) - the modification date of the annotation
# $time (Time) - the modification time of the annotation
pdfjs-annotation-date-string = { $date }, { $time }
# $dateObj (Date) - the modification date and time of the annotation
pdfjs-annotation-date-time-string = { DATETIME($dateObj, dateStyle: "short", timeStyle: "medium") }
# .alt: This is used as a tooltip.
# Variables:
Expand Down
6 changes: 3 additions & 3 deletions l10n/sv-SE/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ pdfjs-rendering-error = Ett fel uppstod vid visning av sidan.
## Annotations

# Variables:
# $date (Date) - the modification date of the annotation
# $time (Time) - the modification time of the annotation
pdfjs-annotation-date-string = { $date } { $time }
# $dateObj (Date) - the modification date and time of the annotation
pdfjs-annotation-date-time-string = { DATETIME($dateObj, dateStyle: "short", timeStyle: "medium") }
# .alt: This is used as a tooltip.
# Variables:
# $type (String) - an annotation type from a list defined in the PDF spec
Expand Down
7 changes: 2 additions & 5 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2242,14 +2242,11 @@ class PopupElement {
modificationDate.classList.add("popupDate");
modificationDate.setAttribute(
"data-l10n-id",
"pdfjs-annotation-date-string"
"pdfjs-annotation-date-time-string"
);
modificationDate.setAttribute(
"data-l10n-args",
JSON.stringify({
date: this.#dateObj.toLocaleDateString(),
time: this.#dateObj.toLocaleTimeString(),
})
JSON.stringify({ dateObj: this.#dateObj.valueOf() })
);
header.append(modificationDate);
}
Expand Down

0 comments on commit f40880c

Please sign in to comment.