mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Utilize Fluent to format numbers and dates in PDFDocumentProperties
The `PDFDocumentProperties` dialog may not display correctly formatted data, 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. At the time when this dialog was introduced that was probably all we could easily do, but with Fluent we're able to improve things since it's got built-in support for formatting numbers and dates. Not only does this simplify the JavaScript code, 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] `toLocaleString`, `toLocaleDateString`, and `toLocaleTimeString`.
This commit is contained in:
parent
037c181af6
commit
d96558836e
2 changed files with 18 additions and 34 deletions
|
@ -239,17 +239,12 @@ class PDFDocumentProperties {
|
|||
return this.l10n.get(`pdfjs-document-properties-${id}`, args);
|
||||
}
|
||||
|
||||
async #parseFileSize(fileSize = 0) {
|
||||
const kb = fileSize / 1024,
|
||||
async #parseFileSize(b = 0) {
|
||||
const kb = b / 1024,
|
||||
mb = kb / 1024;
|
||||
if (!kb) {
|
||||
return undefined;
|
||||
}
|
||||
return this.#getL10nStr(mb >= 1 ? "mb" : "kb", {
|
||||
size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
|
||||
size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
|
||||
size_b: fileSize.toLocaleString(),
|
||||
});
|
||||
return kb
|
||||
? this.#getL10nStr(`size-${mb >= 1 ? "mb" : "kb"}`, { mb, kb, b })
|
||||
: undefined;
|
||||
}
|
||||
|
||||
async #parsePageSize(pageSizeInches, pagesRotation) {
|
||||
|
@ -329,25 +324,15 @@ class PDFDocumentProperties {
|
|||
|
||||
return this.#getL10nStr(
|
||||
`page-size-dimension-${name ? "name-" : ""}string`,
|
||||
{
|
||||
width: width.toLocaleString(),
|
||||
height: height.toLocaleString(),
|
||||
unit,
|
||||
name,
|
||||
orientation,
|
||||
}
|
||||
{ width, height, unit, name, orientation }
|
||||
);
|
||||
}
|
||||
|
||||
async #parseDate(inputDate) {
|
||||
const dateObject = PDFDateString.toDateObject(inputDate);
|
||||
if (!dateObject) {
|
||||
return undefined;
|
||||
}
|
||||
return this.#getL10nStr("date-string", {
|
||||
date: dateObject.toLocaleDateString(),
|
||||
time: dateObject.toLocaleTimeString(),
|
||||
});
|
||||
const dateObj = PDFDateString.toDateObject(inputDate);
|
||||
return dateObj
|
||||
? this.#getL10nStr("date-time-string", { dateObj })
|
||||
: undefined;
|
||||
}
|
||||
|
||||
#parseLinearization(isLinearized) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue