From 06b9455263753747c3a23316639b2d3d49e641a9 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 14 Sep 2018 03:11:40 +0200 Subject: [PATCH] Hard-code the `MOZCENTRAL` build to use the `[other]` plural forms of the matcheCount strings, to prevent errors for PDF files embedded in iframe/object tags The built-in PDF Viewer (in Firefox) cannot use the browser findbar when PDF files are embedded in e.g. iframe/object tags, and the PDF.js findbar (i.e. `PDFFindBar`) will thus be used instead in those cases. This is slightly problematic, since the `MOZCENTRAL` version of the viewer uses a special, slimmed down, version of the `l10n.js` file that doesn't (currently) support plural forms. To prevent the matchesCounter from breaking completely in this edge-case, temporarily hard-code the plural form to use the default `[other]` version of the locale strings. --- web/pdf_find_bar.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/web/pdf_find_bar.js b/web/pdf_find_bar.js index a9f2e47d7a52c..5cd07710c123d 100644 --- a/web/pdf_find_bar.js +++ b/web/pdf_find_bar.js @@ -161,16 +161,33 @@ class PDFFindBar { if (total) { if (total > limit) { - matchesCountMsg = this.l10n.get('find_matches_count_limit', { - n: limit, - limit: limit.toLocaleString(), - }, 'More than {{limit}} match' + (limit !== 1 ? 'es' : '')); + if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('MOZCENTRAL')) { + // TODO: Remove this hard-coded `[other]` form once plural support has + // been implemented in the mozilla-central specific `l10n.js` file. + matchesCountMsg = this.l10n.get('find_matches_count_limit[other]', { + limit: limit.toLocaleString(), + }, 'More than {{limit}} matches'); + } else { + matchesCountMsg = this.l10n.get('find_matches_count_limit', { + n: limit, + limit: limit.toLocaleString(), + }, 'More than {{limit}} match' + (limit !== 1 ? 'es' : '')); + } } else { - matchesCountMsg = this.l10n.get('find_matches_count', { - n: total, - current: current.toLocaleString(), - total: total.toLocaleString(), - }, '{{current}} of {{total}} match' + (total !== 1 ? 'es' : '')); + if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('MOZCENTRAL')) { + // TODO: Remove this hard-coded `[other]` form once plural support has + // been implemented in the mozilla-central specific `l10n.js` file. + matchesCountMsg = this.l10n.get('find_matches_count[other]', { + current: current.toLocaleString(), + total: total.toLocaleString(), + }, '{{current}} of {{total}} matches'); + } else { + matchesCountMsg = this.l10n.get('find_matches_count', { + n: total, + current: current.toLocaleString(), + total: total.toLocaleString(), + }, '{{current}} of {{total}} match' + (total !== 1 ? 'es' : '')); + } } } Promise.resolve(matchesCountMsg).then((msg) => {