Skip to content

Commit

Permalink
Bug 1323415 - Add reader mode time estimate pluralization strings. r=…
Browse files Browse the repository at this point in the history
…gijs

Changes the time estimate string to use the pluralization library
so different localizations will be able to localize correctly.

--HG--
extra : rebase_source : 05d201346b0a4ad72ba5922d8c86f8dcba5bf1f0
  • Loading branch information
fiveNinePlusR committed Dec 19, 2016
1 parent 157bf6a commit 9a1f634
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
10 changes: 8 additions & 2 deletions toolkit/components/reader/AboutReader.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm
XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry", "resource://gre/modules/UITelemetry.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "gChromeRegistry",
"@mozilla.org/chrome/chrome-registry;1", Ci.nsIXULChromeRegistry);
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", "resource://gre/modules/PluralForm.jsm");

var gStrings = Services.strings.createBundle("chrome://global/locale/aboutReader.properties");

Expand Down Expand Up @@ -752,11 +753,16 @@ AboutReader.prototype = {
},

_formatReadTime(slowEstimate, fastEstimate) {
let displayStringKey = "aboutReader.estimatedReadTimeRange1";

// only show one reading estimate when they are the same value
if (slowEstimate == fastEstimate) {
return gStrings.formatStringFromName("aboutReader.estimatedReadTimeValue", [slowEstimate], 1);
displayStringKey = "aboutReader.estimatedReadTimeValue1";
}

return gStrings.formatStringFromName("aboutReader.estimatedReadTimeRange", [fastEstimate, slowEstimate], 2);
return PluralForm.get(slowEstimate, gStrings.GetStringFromName(displayStringKey))
.replace("#1", fastEstimate)
.replace("#2", slowEstimate);
},

_showError: function() {
Expand Down
1 change: 1 addition & 0 deletions toolkit/components/reader/test/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ support-files =
support-files =
readerModeArticle.html
readerModeArticleShort.html
readerModeArticleMedium.html
24 changes: 22 additions & 2 deletions toolkit/components/reader/test/browser_readerMode_readingTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add_task(function* () {
// make sure there is a reading time on the page and that it displays the correct information
let readingTimeElement = content.document.getElementById("reader-estimated-time");
ok(readingTimeElement, "Reading time element should be in document");
is(readingTimeElement.textContent, "9-12 min", "Reading time should be '9-12 min'");
is(readingTimeElement.textContent, "9-12 minutes", "Reading time should be '9-12 minutes'");
});
});
});
Expand All @@ -39,7 +39,27 @@ add_task(function* () {
// make sure there is a reading time on the page and that it displays the correct information
let readingTimeElement = content.document.getElementById("reader-estimated-time");
ok(readingTimeElement, "Reading time element should be in document");
is(readingTimeElement.textContent, "1 min", "Reading time should be '1 min'");
is(readingTimeElement.textContent, "1 minute", "Reading time should be '1 minute'");
});
});
});

/**
* Test that the reader mode correctly calculates and displays the
* estimated reading time for a medium article where a single number
* is displayed.
*/
add_task(function* () {
yield BrowserTestUtils.withNewTab(TEST_PATH + "readerModeArticleMedium.html", function* (browser) {
let pageShownPromise = BrowserTestUtils.waitForContentEvent(browser, "AboutReaderContentReady");
let readerButton = document.getElementById("reader-mode-button");
readerButton.click();
yield pageShownPromise;
yield ContentTask.spawn(browser, null, function* () {
// make sure there is a reading time on the page and that it displays the correct information
let readingTimeElement = content.document.getElementById("reader-estimated-time");
ok(readingTimeElement, "Reading time element should be in document");
is(readingTimeElement.textContent, "3 minutes", "Reading time should be '3 minutes'");
});
});
});
16 changes: 16 additions & 0 deletions toolkit/components/reader/test/readerModeArticleMedium.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>Article title</title>
<meta name="description" content="This is the article description." />
</head>
<body>
<header>Site header</header>
<div>
<h1>Article title</h1>
<h2 class="author">by Jane Doe</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetu</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetu</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetu</p>
</body>
</html>
17 changes: 15 additions & 2 deletions toolkit/locales/en-US/chrome/global/aboutReader.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,21 @@ aboutReader.colorScheme.dark=Dark
aboutReader.colorScheme.sepia=Sepia
aboutReader.colorScheme.auto=Auto

aboutReader.estimatedReadTimeValue=%S min
aboutReader.estimatedReadTimeRange=%S-%S min
# LOCALIZATION NOTE (aboutReader.estimatedReadTimeValue1): Semi-colon list of plural forms.
# See: http://developer.mozilla.org/en/docs/Localization_and_Plurals
# #1 is the number of minutes it is estimated to take to read the article
# example: `3 minutes`
aboutReader.estimatedReadTimeValue1=#1 minute;#1 minutes

#LOCALIZATION NOTE (aboutReader.estimatedReadingTimeRange1): Semi-colon list of plural forms.
# See: http://developer.mozilla.org/en/docs/Localization_and_Plurals
# When there is some uncertainty in how long the article will take to read show a range of
# minutes it is expected to take.
# #1 is the number of minutes it is estimated to take to read the article for a fast reader
# #2 is the number of minutes it is estimated to take to read the article for a slow reader
# #2 is the variable used to determine the plural form to use.
# example: `5-8 minutes`
aboutReader.estimatedReadTimeRange1=#1-#2 minute;#1-#2 minutes

# LOCALIZATION NOTE (aboutReader.fontType.serif, aboutReader.fontType.sans-serif):
# These are the styles of typeface that are options in the reader view controls.
Expand Down

0 comments on commit 9a1f634

Please sign in to comment.