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.
This commit is contained in:
Jonas Jenwald 2018-03-20 14:26:49 +01:00
parent fc0038d609
commit d86b816c2b
3 changed files with 49 additions and 3 deletions

View File

@ -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…

View File

@ -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…

View File

@ -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}})');
});
}