From d86b816c2b9d4146b2aea80dc86461ad55e3555c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald <jonas.jenwald@gmail.com> Date: Tue, 20 Mar 2018 14:26:49 +0100 Subject: [PATCH] Display the names, for a couple of standard page sizes, in the document properties dialog Please note that this patch *purposely* doesn't add every standard (or semi-standard) page name in existence, but rather only a few common ones. This is done to lessen the burden on localizers, since it's quite possible that all of the page names could need translation (depending on locale). It's easy to add more standard page sizes in the future, but we should take care to *only* add those that are very commonly used in actual PDF files. --- l10n/en-US/viewer.properties | 8 ++++++++ l10n/sv-SE/viewer.properties | 8 ++++++++ web/pdf_document_properties.js | 36 +++++++++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/l10n/en-US/viewer.properties b/l10n/en-US/viewer.properties index 324e843ba..3f4723eb2 100644 --- a/l10n/en-US/viewer.properties +++ b/l10n/en-US/viewer.properties @@ -94,10 +94,18 @@ document_properties_page_size_unit_inches=in document_properties_page_size_unit_millimeters=mm document_properties_page_size_orientation_portrait=portrait document_properties_page_size_orientation_landscape=landscape +document_properties_page_size_name_a3=A3 +document_properties_page_size_name_a4=A4 +document_properties_page_size_name_letter=Letter +document_properties_page_size_name_legal=Legal # LOCALIZATION NOTE (document_properties_page_size_dimension_string): # "{{width}}", "{{height}}", {{unit}}, and {{orientation}} will be replaced by # the size, respectively their unit of measurement and orientation, of the (current) page. document_properties_page_size_dimension_string={{width}} × {{height}} {{unit}} ({{orientation}}) +# LOCALIZATION NOTE (document_properties_page_size_dimension_name_string): +# "{{width}}", "{{height}}", {{unit}}, {{name}}, and {{orientation}} will be replaced by +# the size, respectively their unit of measurement, name, and orientation, of the (current) page. +document_properties_page_size_dimension_name_string={{width}} × {{height}} {{unit}} ({{name}}, {{orientation}}) document_properties_close=Close print_progress_message=Preparing document for printing… diff --git a/l10n/sv-SE/viewer.properties b/l10n/sv-SE/viewer.properties index b31720635..29ac19836 100644 --- a/l10n/sv-SE/viewer.properties +++ b/l10n/sv-SE/viewer.properties @@ -94,10 +94,18 @@ document_properties_page_size_unit_inches=tum document_properties_page_size_unit_millimeters=mm document_properties_page_size_orientation_portrait=stående document_properties_page_size_orientation_landscape=liggande +document_properties_page_size_name_a3=A3 +document_properties_page_size_name_a4=A4 +document_properties_page_size_name_letter=Letter +document_properties_page_size_name_legal=Legal # LOCALIZATION NOTE (document_properties_page_size_dimension_string): # "{{width}}", "{{height}}", {{unit}}, and {{orientation}} will be replaced by # the size, respectively their unit of measurement and orientation, of the (current) page. document_properties_page_size_dimension_string={{width}} × {{height}} {{unit}} ({{orientation}}) +# LOCALIZATION NOTE (document_properties_page_size_dimension_name_string): +# "{{width}}", "{{height}}", {{unit}}, {{name}}, and {{orientation}} will be replaced by +# the size, respectively their unit of measurement, name, and orientation, of the (current) page. +document_properties_page_size_dimension_name_string={{width}} × {{height}} {{unit}} ({{name}}, {{orientation}}) document_properties_close=Stäng print_progress_message=Förbereder sidor för utskrift… diff --git a/web/pdf_document_properties.js b/web/pdf_document_properties.js index 9513014f3..b030705a8 100644 --- a/web/pdf_document_properties.js +++ b/web/pdf_document_properties.js @@ -24,6 +24,24 @@ const DEFAULT_FIELD_CONTENT = '-'; // See https://en.wikibooks.org/wiki/Lentis/Conversion_to_the_Metric_Standard_in_the_United_States const NON_METRIC_LOCALES = ['en-us', 'en-lr', 'my']; +// Should use the format: `width x height`, in portrait orientation. +// See https://en.wikipedia.org/wiki/Paper_size +const US_PAGE_NAMES = { + '8.5x11': 'Letter', + '8.5x14': 'Legal', +}; +const METRIC_PAGE_NAMES = { + '297x420': 'A3', + '210x297': 'A4', +}; + +function getPageName(size, isPortrait, pageNames) { + const width = (isPortrait ? size.width : size.height); + const height = (isPortrait ? size.height : size.width); + + return pageNames[`${width}x${height}`]; +} + /** * @typedef {Object} PDFDocumentPropertiesOptions * @property {string} overlayName - Name/identifier for the overlay. @@ -279,21 +297,33 @@ class PDFDocumentProperties { height: Math.round(pageSizeInches.height * 25.4 * 10) / 10, }; + let pageName = null; + const name = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || + getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES); + if (name) { + pageName = this.l10n.get('document_properties_page_size_name_' + + name.toLowerCase(), null, name); + } + return Promise.all([ (this._isNonMetricLocale ? sizeInches : sizeMillimeters), this.l10n.get('document_properties_page_size_unit_' + (this._isNonMetricLocale ? 'inches' : 'millimeters'), null, this._isNonMetricLocale ? 'in' : 'mm'), + pageName, this.l10n.get('document_properties_page_size_orientation_' + (isPortrait ? 'portrait' : 'landscape'), null, isPortrait ? 'portrait' : 'landscape'), - ]).then(([{ width, height, }, unit, orientation]) => { - return this.l10n.get('document_properties_page_size_dimension_string', { + ]).then(([{ width, height, }, unit, name, orientation]) => { + return this.l10n.get('document_properties_page_size_dimension_' + + (name ? 'name_' : '') + 'string', { width: width.toLocaleString(), height: height.toLocaleString(), unit, + name, orientation, - }, '{{width}} × {{height}} {{unit}} ({{orientation}})'); + }, '{{width}} × {{height}} {{unit}} (' + + (name ? '{{name}}, ' : '') + '{{orientation}})'); }); }