Skip to content

Commit cd99be0

Browse files
Merge pull request #18638 from Snuffleupagus/PDFDocumentProperties-l10n-functions
Utilize Fluent to format numbers and dates in `PDFDocumentProperties`/`AnnotationLayer`
2 parents de365b6 + 6ce9f97 commit cd99be0

File tree

3 files changed

+22
-42
lines changed

3 files changed

+22
-42
lines changed

l10n/en-US/viewer.ftl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ pdfjs-document-properties-file-name = File name:
113113
pdfjs-document-properties-file-size = File size:
114114
115115
# Variables:
116-
# $size_kb (Number) - the PDF file size in kilobytes
117-
# $size_b (Number) - the PDF file size in bytes
118-
pdfjs-document-properties-kb = { $size_kb } KB ({ $size_b } bytes)
116+
# $kb (Number) - the PDF file size in kilobytes
117+
# $b (Number) - the PDF file size in bytes
118+
pdfjs-document-properties-size-kb = { NUMBER($kb, maximumSignificantDigits: 3) } KB ({ $b } bytes)
119119
120120
# Variables:
121-
# $size_mb (Number) - the PDF file size in megabytes
122-
# $size_b (Number) - the PDF file size in bytes
123-
pdfjs-document-properties-mb = { $size_mb } MB ({ $size_b } bytes)
121+
# $mb (Number) - the PDF file size in megabytes
122+
# $b (Number) - the PDF file size in bytes
123+
pdfjs-document-properties-size-mb = { NUMBER($mb, maximumSignificantDigits: 3) } MB ({ $b } bytes)
124124
125125
pdfjs-document-properties-title = Title:
126126
pdfjs-document-properties-author = Author:
@@ -130,9 +130,8 @@ pdfjs-document-properties-creation-date = Creation Date:
130130
pdfjs-document-properties-modification-date = Modification Date:
131131
132132
# Variables:
133-
# $date (Date) - the creation/modification date of the PDF file
134-
# $time (Time) - the creation/modification time of the PDF file
135-
pdfjs-document-properties-date-string = { $date }, { $time }
133+
# $dateObj (Date) - the creation/modification date and time of the PDF file
134+
pdfjs-document-properties-date-time-string = { DATETIME($dateObj, dateStyle: "short", timeStyle: "medium") }
136135
137136
pdfjs-document-properties-creator = Creator:
138137
pdfjs-document-properties-producer = PDF Producer:
@@ -284,9 +283,8 @@ pdfjs-rendering-error = An error occurred while rendering the page.
284283
## Annotations
285284

286285
# Variables:
287-
# $date (Date) - the modification date of the annotation
288-
# $time (Time) - the modification time of the annotation
289-
pdfjs-annotation-date-string = { $date }, { $time }
286+
# $dateObj (Date) - the modification date and time of the annotation
287+
pdfjs-annotation-date-time-string = { DATETIME($dateObj, dateStyle: "short", timeStyle: "medium") }
290288
291289
# .alt: This is used as a tooltip.
292290
# Variables:

src/display/annotation_layer.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,14 +2242,11 @@ class PopupElement {
22422242
modificationDate.classList.add("popupDate");
22432243
modificationDate.setAttribute(
22442244
"data-l10n-id",
2245-
"pdfjs-annotation-date-string"
2245+
"pdfjs-annotation-date-time-string"
22462246
);
22472247
modificationDate.setAttribute(
22482248
"data-l10n-args",
2249-
JSON.stringify({
2250-
date: this.#dateObj.toLocaleDateString(),
2251-
time: this.#dateObj.toLocaleTimeString(),
2252-
})
2249+
JSON.stringify({ dateObj: this.#dateObj.valueOf() })
22532250
);
22542251
header.append(modificationDate);
22552252
}

web/pdf_document_properties.js

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,12 @@ class PDFDocumentProperties {
239239
return this.l10n.get(`pdfjs-document-properties-${id}`, args);
240240
}
241241

242-
async #parseFileSize(fileSize = 0) {
243-
const kb = fileSize / 1024,
242+
async #parseFileSize(b = 0) {
243+
const kb = b / 1024,
244244
mb = kb / 1024;
245-
if (!kb) {
246-
return undefined;
247-
}
248-
return this.#getL10nStr(mb >= 1 ? "mb" : "kb", {
249-
size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
250-
size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
251-
size_b: fileSize.toLocaleString(),
252-
});
245+
return kb
246+
? this.#getL10nStr(`size-${mb >= 1 ? "mb" : "kb"}`, { mb, kb, b })
247+
: undefined;
253248
}
254249

255250
async #parsePageSize(pageSizeInches, pagesRotation) {
@@ -329,25 +324,15 @@ class PDFDocumentProperties {
329324

330325
return this.#getL10nStr(
331326
`page-size-dimension-${name ? "name-" : ""}string`,
332-
{
333-
width: width.toLocaleString(),
334-
height: height.toLocaleString(),
335-
unit,
336-
name,
337-
orientation,
338-
}
327+
{ width, height, unit, name, orientation }
339328
);
340329
}
341330

342331
async #parseDate(inputDate) {
343-
const dateObject = PDFDateString.toDateObject(inputDate);
344-
if (!dateObject) {
345-
return undefined;
346-
}
347-
return this.#getL10nStr("date-string", {
348-
date: dateObject.toLocaleDateString(),
349-
time: dateObject.toLocaleTimeString(),
350-
});
332+
const dateObj = PDFDateString.toDateObject(inputDate);
333+
return dateObj
334+
? this.#getL10nStr("date-time-string", { dateObj })
335+
: undefined;
351336
}
352337

353338
#parseLinearization(isLinearized) {

0 commit comments

Comments
 (0)