Skip to content

Commit

Permalink
Hard-code the MOZCENTRAL build to use the [other] plural forms of…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Snuffleupagus committed Sep 14, 2018
1 parent 24cbae9 commit 5ade875
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions web/pdf_find_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 5ade875

Please sign in to comment.