Bug 1504457 Migrate subcribe.js to Fluent r=flod,jaws

Differential Revision: https://phabricator.services.mozilla.com/D10863

--HG--
extra : rebase_source : d0435457f5dac0d455e9e1ab8fb164a0e02d695e
This commit is contained in:
Collin Wing 2018-11-07 13:08:43 +00:00
Родитель d0ec6a60ce
Коммит 8e6579676e
4 изменённых файлов: 55 добавлений и 30 удалений

Просмотреть файл

@ -10,14 +10,9 @@
*/
window.addEventListener("load", function() {
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm", {});
// Timeout for the subscribe XHR.
const REQUEST_TIMEOUT = 5000;
const ABOUTDEVTOOLS_STRINGS = "chrome://devtools-startup/locale/aboutdevtools.properties";
const aboutDevtoolsBundle = Services.strings.createBundle(ABOUTDEVTOOLS_STRINGS);
const emailInput = document.getElementById("email");
const newsletterErrors = document.getElementById("newsletter-errors");
const newsletterForm = document.getElementById("newsletter-form");
@ -31,11 +26,11 @@ window.addEventListener("load", function() {
* @param {Array} errors
* Array of strings, each item being an error message to display.
*/
function updateErrorPanel(errors) {
async function updateErrorPanel(errors) {
clearErrorPanel();
if (!errors || errors.length == 0) {
errors = [aboutDevtoolsBundle.GetStringFromName("newsletter.error.unknown")];
errors = [await document.l10n.formatValues([{id: "newsletter-error-unknown"}])];
}
// Create errors markup.
@ -92,7 +87,7 @@ window.addEventListener("load", function() {
const xhr = new XMLHttpRequest();
xhr.onload = function(r) {
xhr.onload = async function(r) {
if (r.target.status >= 200 && r.target.status < 300) {
const {response} = r.target;
@ -107,8 +102,9 @@ window.addEventListener("load", function() {
} else {
const {status, statusText} = r.target;
const statusInfo = `${status} - ${statusText}`;
const error = aboutDevtoolsBundle
.formatStringFromName("newsletter.error.common", [statusInfo], 1);
const error = await document.l10n.formatValues([
{ id: "newsletter-error-common", args: { errorDescription: statusInfo } },
]);
updateErrorPanel([error]);
}
};
@ -117,8 +113,10 @@ window.addEventListener("load", function() {
updateErrorPanel();
};
xhr.ontimeout = () => {
const error = aboutDevtoolsBundle.GetStringFromName("newsletter.error.timeout");
xhr.ontimeout = async () => {
const error = await document.l10n.formatValues([
{ id: "newsletter-error-timeout" },
]);
updateErrorPanel([error]);
};

Просмотреть файл

@ -48,5 +48,10 @@ features-performance-desc = Unblock bottlenecks, streamline processes, optimize
features-memory-title = Memory
features-memory-desc = Find memory leaks and make your application zippy. <a data-l10n-name="learn-more">{ features-learn-more }</a>
# Variables:
# $errorDescription (String) - The error that occurred e.g. 404 - Not Found
newsletter-error-common = Subscription request failed ({ $errorDescription }).
newsletter-error-unknown = An unexpected error occurred.
newsletter-error-timeout = Subscription request timed out.
# Variables:
# $shortcut (String) - The keyboard shortcut used for the tool
welcome-message = Youve successfully enabled Developer Tools! To get started, explore the Web Developer menu or open the tools with { $shortcut }.

Просмотреть файл

@ -1,18 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# LOCALIZATION NOTE These strings are used in the about:devtools page.
# LOCALIZATION NOTE (newsletter.error.common): error text displayed when the newsletter
# subscription failed. The argument will be replaced with request's status code and status
# text (e.g. "404 - Not Found")
newsletter.error.common=Subscription request failed (%S).
# LOCALIZATION NOTE (newsletter.error.unknown): error text displayed when the newsletter
# subscription failed for an unexpected reason.
newsletter.error.unknown=An unexpected error occurred.
# LOCALIZATION NOTE (newsletter.error.timeout): error text displayed when the newsletter
# subscription timed out.
newsletter.error.timeout=Subscription request timed out.

Просмотреть файл

@ -0,0 +1,40 @@
from __future__ import absolute_import
import fluent.syntax.ast as FTL
from fluent.migrate.helpers import transforms_from
from fluent.migrate.helpers import VARIABLE_REFERENCE
from fluent.migrate.helpers import TERM_REFERENCE
from fluent.migrate.helpers import MESSAGE_REFERENCE
from fluent.migrate import REPLACE
from fluent.migrate import COPY
from fluent.migrate import CONCAT
def migrate(ctx):
"""Bug 1504457 - Migrate subscribe.js strings of about:devtools to Fluent, part {index}"""
ctx.add_transforms(
"devtools/startup/aboutDevTools.ftl",
"devtools/startup/aboutDevTools.ftl",
transforms_from(
"""
newsletter-error-unknown = { COPY("devtools/startup/aboutdevtools.properties", "newsletter.error.unknown")}
newsletter-error-timeout = { COPY("devtools/startup/aboutdevtools.properties", "newsletter.error.timeout")}
"""
)
)
ctx.add_transforms(
"devtools/startup/aboutDevTools.ftl",
"devtools/startup/aboutDevTools.ftl",
[
FTL.Message(
id=FTL.Identifier("newsletter-error-common"),
value=REPLACE(
"devtools/startup/aboutdevtools.properties",
"newsletter.error.common",
{
"%S": VARIABLE_REFERENCE("errorDescription")
}
)
)
]
)