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 25, 2024
1 parent d965588 commit 6ce9f97
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 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
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 6ce9f97

Please sign in to comment.