From 6ce9f97943fd04830588dceea510c76e3fcd606b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 21 Aug 2024 21:43:42 +0200 Subject: [PATCH] Utilize Fluent to format dates in the `AnnotationLayer` 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`. --- l10n/en-US/viewer.ftl | 5 ++--- src/display/annotation_layer.js | 7 ++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/l10n/en-US/viewer.ftl b/l10n/en-US/viewer.ftl index cea54a28242ae..bd7bb4ac0fa44 100644 --- a/l10n/en-US/viewer.ftl +++ b/l10n/en-US/viewer.ftl @@ -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: diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index dff737b6ca6d7..9d8ad8dceeef2 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -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); }