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 21, 2024
1 parent 58c11a8 commit cdc500c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 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-string1 = { DATETIME($dateObj, dateStyle: "short") }, { DATETIME($dateObj, 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-string1 = { DATETIME($dateObj, dateStyle: "short") }, { DATETIME($dateObj, 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
5 changes: 2 additions & 3 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2242,13 +2242,12 @@ class PopupElement {
modificationDate.classList.add("popupDate");
modificationDate.setAttribute(
"data-l10n-id",
"pdfjs-annotation-date-string"
"pdfjs-annotation-date-string1"
);
modificationDate.setAttribute(
"data-l10n-args",
JSON.stringify({
date: this.#dateObj.toLocaleDateString(),
time: this.#dateObj.toLocaleTimeString(),
dateObj: this.#dateObj.valueOf(),
})
);
header.append(modificationDate);
Expand Down

0 comments on commit cdc500c

Please sign in to comment.