Bug 1508131 - Migrate about:serviceworkers to use Fluent for localization r=Gijs,flod,zbraniecki

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Qinghao_Jack_Song 2018-12-04 23:27:45 +00:00
parent fb49499bf5
commit 2139f380ca
7 changed files with 227 additions and 99 deletions

View File

@ -0,0 +1,147 @@
# coding=utf8
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
from __future__ import absolute_import
import fluent.syntax.ast as FTL
from fluent.migrate.helpers import transforms_from
from fluent.migrate import COPY
from fluent.migrate import CONCAT
from fluent.migrate import REPLACE
from fluent.migrate.helpers import TERM_REFERENCE
from fluent.migrate.helpers import VARIABLE_REFERENCE
def migrate(ctx):
"""Bug 1508131 - Migrate about:serviceworkers to use Fluent for localization, part {index}."""
ctx.add_transforms(
"toolkit/toolkit/about/aboutServiceWorkers.ftl",
"toolkit/toolkit/about/aboutServiceWorkers.ftl",
transforms_from(
"""
about-service-workers-title = { COPY("toolkit/chrome/global/aboutServiceWorkers.dtd", "aboutServiceWorkers.title") }
about-service-workers-main-title = { COPY("toolkit/chrome/global/aboutServiceWorkers.dtd", "aboutServiceWorkers.maintitle") }
about-service-workers-warning-not-enabled = { COPY("toolkit/chrome/global/aboutServiceWorkers.dtd", "aboutServiceWorkers.warning_not_enabled") }
about-service-workers-warning-no-service-workers = { COPY("toolkit/chrome/global/aboutServiceWorkers.dtd", "aboutServiceWorkers.warning_no_serviceworkers") }
update-button = { COPY("toolkit/chrome/global/aboutServiceWorkers.properties", "update") }
unregister-button = { COPY("toolkit/chrome/global/aboutServiceWorkers.properties", "unregister") }
unregister-error = { COPY("toolkit/chrome/global/aboutServiceWorkers.properties", "unregisterError") }
waiting = { COPY("toolkit/chrome/global/aboutServiceWorkers.properties", "waiting") }
""")
)
ctx.add_transforms(
"toolkit/toolkit/about/aboutServiceWorkers.ftl",
"toolkit/toolkit/about/aboutServiceWorkers.ftl",
[
FTL.Message(
id=FTL.Identifier("origin-title"),
value=REPLACE(
"toolkit/chrome/global/aboutServiceWorkers.properties",
"title",
{
"%S": VARIABLE_REFERENCE("originTitle"),
},
)
),
FTL.Message(
id=FTL.Identifier("app-title"),
value=REPLACE(
"toolkit/chrome/global/aboutServiceWorkers.properties",
"b2gtitle",
{
"%1$S": TERM_REFERENCE("-brand-short-name"),
"%2$S": VARIABLE_REFERENCE("appId"),
"%3$S": VARIABLE_REFERENCE("isInIsolatedElement"),
},
)
),
FTL.Message(
id=FTL.Identifier("scope"),
value=CONCAT(
FTL.TextElement('<strong>'),
COPY(
"toolkit/chrome/global/aboutServiceWorkers.properties",
"scope"
),
FTL.TextElement('</strong> { $name }'),
)
),
FTL.Message(
id=FTL.Identifier("script-spec"),
value=CONCAT(
FTL.TextElement('<strong>'),
COPY(
"toolkit/chrome/global/aboutServiceWorkers.properties",
"scriptSpec"
),
FTL.TextElement('</strong> <a data-l10n-name="link">{ $url }</a>'),
)
),
FTL.Message(
id=FTL.Identifier("current-worker-url"),
value=CONCAT(
FTL.TextElement('<strong>'),
COPY(
"toolkit/chrome/global/aboutServiceWorkers.properties",
"currentWorkerURL"
),
FTL.TextElement('</strong> <a data-l10n-name="link">{ $url }</a>'),
)
),
FTL.Message(
id=FTL.Identifier("active-cache-name"),
value=CONCAT(
FTL.TextElement('<strong>'),
COPY(
"toolkit/chrome/global/aboutServiceWorkers.properties",
"activeCacheName"
),
FTL.TextElement('</strong> { $name }')
)
),
FTL.Message(
id=FTL.Identifier("waiting-cache-name"),
value=CONCAT(
FTL.TextElement('<strong>'),
COPY(
"toolkit/chrome/global/aboutServiceWorkers.properties",
"waitingCacheName"
),
FTL.TextElement('</strong> { $name }')
)
),
FTL.Message(
id=FTL.Identifier("push-end-point-waiting"),
value=CONCAT(
FTL.TextElement('<strong>'),
COPY(
"toolkit/chrome/global/aboutServiceWorkers.properties",
"pushEndpoint"
),
FTL.TextElement('</strong> { waiting }')
)
),
FTL.Message(
id=FTL.Identifier("push-end-point-result"),
value=CONCAT(
FTL.TextElement('<strong>'),
COPY(
"toolkit/chrome/global/aboutServiceWorkers.properties",
"pushEndpoint"
),
FTL.TextElement('</strong> { $name }')
)
),
]
)

View File

@ -7,12 +7,6 @@
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const bundle = Services.strings.createBundle(
"chrome://global/locale/aboutServiceWorkers.properties");
const brandBundle = Services.strings.createBundle(
"chrome://branding/locale/brand.properties");
var gSWM;
var gSWCount = 0;
@ -63,69 +57,61 @@ function init() {
}
}
function display(info, pushService) {
async function display(info, pushService) {
let parent = document.getElementById("serviceworkers");
let div = document.createElement("div");
parent.appendChild(div);
let title = document.createElement("h2");
let titleStr = bundle.formatStringFromName("title", [info.principal.origin], 1);
title.appendChild(document.createTextNode(titleStr));
document.l10n.setAttributes(title, "origin-title", { originTitle: info.principal.origin });
div.appendChild(title);
if (info.principal.appId) {
let b2gtitle = document.createElement("h3");
let trueFalse = bundle.GetStringFromName(info.principal.isInIsolatedMozBrowserElement ? "true" : "false");
let b2gtitleStr =
bundle.formatStringFromName("b2gtitle", [ brandBundle.getString("brandShortName"),
info.principal.appId,
trueFalse], 2);
b2gtitle.appendChild(document.createTextNode(b2gtitleStr));
let trueFalse = info.principal.isInIsolatedMozBrowserElement ? "true" : "false";
document.l10n.setAttributes(b2gtitle, "app-title", { appId: info.principal.appId, isInIsolatedElement: trueFalse });
div.appendChild(b2gtitle);
}
let list = document.createElement("ul");
div.appendChild(list);
function createItem(title, value, makeLink) {
function createItem(l10nId, value, makeLink) {
let item = document.createElement("li");
list.appendChild(item);
let bold = document.createElement("strong");
bold.appendChild(document.createTextNode(title + " "));
bold.setAttribute("data-l10n-name", "item-label");
item.appendChild(bold);
let textNode = document.createTextNode(value);
if (makeLink) {
if (!value) {
document.l10n.setAttributes(item, l10nId);
} else if (makeLink) {
let link = document.createElement("a");
link.href = value;
link.target = "_blank";
link.appendChild(textNode);
link.setAttribute("target", "_blank");
link.setAttribute("data-l10n-name", "link");
link.setAttribute("href", value);
item.appendChild(link);
document.l10n.setAttributes(item, l10nId, { url: value });
} else {
item.appendChild(textNode);
document.l10n.setAttributes(item, l10nId, { name: value });
}
return textNode;
return item;
}
createItem(bundle.GetStringFromName("scope"), info.scope);
createItem(bundle.GetStringFromName("scriptSpec"), info.scriptSpec, true);
createItem("scope", info.scope);
createItem("script-spec", info.scriptSpec, true);
let currentWorkerURL = info.activeWorker ? info.activeWorker.scriptSpec : "";
createItem(bundle.GetStringFromName("currentWorkerURL"), currentWorkerURL, true);
createItem("current-worker-url", currentWorkerURL, true);
let activeCacheName = info.activeWorker ? info.activeWorker.cacheName : "";
createItem(bundle.GetStringFromName("activeCacheName"), activeCacheName);
createItem("active-cache-name", activeCacheName);
let waitingCacheName = info.waitingWorker ? info.waitingWorker.cacheName : "";
createItem(bundle.GetStringFromName("waitingCacheName"), waitingCacheName);
createItem("waiting-cache-name", waitingCacheName);
let pushItem = createItem(bundle.GetStringFromName("pushEndpoint"), bundle.GetStringFromName("waiting"));
let pushItem = createItem("push-end-point-waiting");
if (pushService) {
pushService.getSubscription(info.scope, info.principal, (status, pushRecord) => {
if (Components.isSuccessCode(status)) {
pushItem.data = JSON.stringify(pushRecord);
document.l10n.setAttributes(pushItem, "push-end-point-result", { name: JSON.stringify(pushRecord) });
} else {
dump("about:serviceworkers - retrieving push registration failed\n");
}
@ -133,18 +119,18 @@ function display(info, pushService) {
}
let updateButton = document.createElement("button");
updateButton.appendChild(document.createTextNode(bundle.GetStringFromName("update")));
document.l10n.setAttributes(updateButton, "update-button");
updateButton.onclick = function() {
gSWM.propagateSoftUpdate(info.principal.originAttributes, info.scope);
};
div.appendChild(updateButton);
let unregisterButton = document.createElement("button");
unregisterButton.appendChild(document.createTextNode(bundle.GetStringFromName("unregister")));
document.l10n.setAttributes(unregisterButton, "unregister-button");
div.appendChild(unregisterButton);
let loadingMessage = document.createElement("span");
loadingMessage.appendChild(document.createTextNode(bundle.GetStringFromName("waiting")));
document.l10n.setAttributes(loadingMessage, "waiting");
loadingMessage.classList.add("inactive");
div.appendChild(loadingMessage);
@ -159,8 +145,9 @@ function display(info, pushService) {
}
},
unregisterFailed() {
alert(bundle.GetStringFromName("unregisterError"));
async unregisterFailed() {
let [alertMsg] = await document.l10n.formatValues([{ id: "unregister-error" }]);
alert(alertMsg);
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIServiceWorkerUnregisterCallback]),

View File

@ -6,29 +6,28 @@
<!DOCTYPE html [
<!ENTITY % htmlDTD PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> %htmlDTD;
<!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd"> %globalDTD;
<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd"> %brandDTD;
<!ENTITY % serviceworkersDTD SYSTEM "chrome://global/locale/aboutServiceWorkers.dtd"> %serviceworkersDTD;
]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>&aboutServiceWorkers.title;</title>
<title data-l10n-id="about-service-workers-title"></title>
<link rel="stylesheet" href="chrome://global/skin/about.css" type="text/css" />
<link rel="stylesheet" href="chrome://mozapps/skin/aboutServiceWorkers.css" type="text/css" />
<link rel="localization" href="toolkit/about/aboutServiceWorkers.ftl"/>
<link rel="localization" href="branding/brand.ftl"/>
<script type="application/javascript" src="chrome://global/content/aboutServiceWorkers.js" />
</head>
<body id="body" dir="&locale.dir;">
<body id="body">
<div id="warning_not_enabled" class="warningBackground">
<div class="warningMessage">&aboutServiceWorkers.warning_not_enabled;</div>
<div class="warningMessage" data-l10n-id="about-service-workers-warning-not-enabled"></div>
</div>
<div id="warning_no_serviceworkers" class="warningBackground">
<div class="warningMessage">&aboutServiceWorkers.warning_no_serviceworkers;</div>
<div class="warningMessage" data-l10n-id="about-service-workers-warning-no-service-workers"></div>
</div>
<div id="serviceworkers" class="tab active">
<h1>&aboutServiceWorkers.maintitle;</h1>
<h1 data-l10n-id="about-service-workers-main-title"></h1>
</div>
</body>
</html>

View File

@ -1,12 +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 the term "Service Workers" should not be translated. -->
<!ENTITY aboutServiceWorkers.title "About Service Workers">
<!-- LOCALIZATION NOTE the term "Service Workers" should not be translated. -->
<!ENTITY aboutServiceWorkers.maintitle "Registered Service Workers">
<!-- LOCALIZATION NOTE the term "Service Workers" should not be translated. -->
<!ENTITY aboutServiceWorkers.warning_not_enabled "Service Workers are not enabled.">
<!-- LOCALIZATION NOTE the term "Service Workers" should not be translated. -->
<!ENTITY aboutServiceWorkers.warning_no_serviceworkers "No Service Workers registered.">

View File

@ -1,36 +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/.
title = Origin: %S
# LOCALIZATION NOTE: %1$S is brandShortName, %2$2 is the application ID, and $%$3 is true/false value.
# LOCALIZATION NOTE: the term "InBrowserElement" should not be translated
b2gtitle = %1$S Application ID %2$S - InBrowserElement %3$S
scope = Scope:
scriptSpec = Script Spec:
# LOCALIZATION NOTE: the term "Worker" should not be translated.
currentWorkerURL = Current Worker URL:
activeCacheName = Active Cache Name:
waitingCacheName = Waiting Cache Name:
true = true
false = false
# LOCALIZATION NOTE this term is used as a button label (verb, not noun).
update = Update
unregister = Unregister
waiting = Waiting…
# LOCALIZATION NOTE: the term "Service Worker" should not translated.
unregisterError = Failed to unregister this Service Worker.
pushEndpoint = Push Endpoint:

View File

@ -0,0 +1,45 @@
# 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/.
### The term "Service Workers" and "Workers" should not be translated
about-service-workers-title = About Service Workers
about-service-workers-main-title = Registered Service Workers
about-service-workers-warning-not-enabled = Service Workers are not enabled.
about-service-workers-warning-no-service-workers = No Service Workers registered.
# The original title of service workers' information
#
# Variables:
# $originTitle: original title
origin-title = Origin: { $originTitle }
# Show if app id is in isolated browser element, the term "InBrowserElement" should not be translated
#
# Variables:
# $appId: the application ID
# $isInIsolatedElement: "true" or "false" based on if the app id is in isolate element
app-title = { -brand-short-name } Application ID { $appId } - InBrowserElement { $isInIsolatedElement }
## These strings are for showing the information of workers.
##
## Variables:
## $name: the name of scope, active cache, waiting cache and the push end point.
## $url: the url of script specification and current worker.
scope = <strong>Scope:</strong> { $name }
script-spec = <strong>Script Spec:</strong> <a data-l10n-name="link">{ $url }</a>
current-worker-url = <strong>Current Worker URL:</strong> <a data-l10n-name="link">{ $url }</a>
active-cache-name = <strong>Active Cache Name:</strong> { $name }
waiting-cache-name = <strong>Waiting Cache Name:</strong> { $name }
push-end-point-waiting = <strong>Push Endpoint:</strong> { waiting }
push-end-point-result = <strong>Push Endpoint:</strong> { $name }
# This term is used as a button label (verb, not noun).
update-button = Update
unregister-button = Unregister
unregister-error = Failed to unregister this Service Worker.
waiting = Waiting…

View File

@ -12,8 +12,6 @@
locale/@AB_CD@/global/aboutReader.properties (%chrome/global/aboutReader.properties)
locale/@AB_CD@/global/aboutRights.dtd (%chrome/global/aboutRights.dtd)
locale/@AB_CD@/global/aboutStudies.properties (%chrome/global/aboutStudies.properties)
locale/@AB_CD@/global/aboutServiceWorkers.dtd (%chrome/global/aboutServiceWorkers.dtd)
locale/@AB_CD@/global/aboutServiceWorkers.properties (%chrome/global/aboutServiceWorkers.properties)
locale/@AB_CD@/global/aboutSupport.dtd (%chrome/global/aboutSupport.dtd)
locale/@AB_CD@/global/aboutSupport.properties (%chrome/global/aboutSupport.properties)
locale/@AB_CD@/global/aboutTelemetry.dtd (%chrome/global/aboutTelemetry.dtd)