Bug 1303883 - Localize Fennec's about:downloads with L20n. r?Pike
MozReview-Commit-ID: DCulB0nU3OY
--- a/mobile/android/chrome/content/aboutDownloads.js
+++ b/mobile/android/chrome/content/aboutDownloads.js
@@ -9,20 +9,16 @@ Cu.import("resource://gre/modules/XPCOMU
XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DownloadUtils", "resource://gre/modules/DownloadUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Messaging", "resource://gre/modules/Messaging.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", "resource://gre/modules/PluralForm.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm");
-var gStrings = Services.strings.createBundle("chrome://browser/locale/aboutDownloads.properties");
-XPCOMUtils.defineLazyGetter(this, "strings",
- () => Services.strings.createBundle("chrome://browser/locale/aboutDownloads.properties"));
-
function deleteDownload(download) {
download.finalize(true).then(null, Cu.reportError);
OS.File.remove(download.target.path).then(null, ex => {
if (!(ex instanceof OS.File.Error && ex.becauseNoSuchFile)) {
Cu.reportError(ex);
}
});
}
@@ -202,29 +198,30 @@ var downloadLists = {
},
removeFinished: function () {
let finished = this.finished;
if (finished.length == 0) {
return;
}
- let title = strings.GetStringFromName("downloadAction.deleteAll");
- let messageForm = strings.GetStringFromName("downloadMessage.deleteAll");
- let message = PluralForm.get(finished.length, messageForm).replace("#1", finished.length);
-
- if (Services.prompt.confirm(null, title, message)) {
- Downloads.getList(Downloads.ALL)
- .then(list => {
- for (let download of finished) {
- list.remove(download).then(null, Cu.reportError);
- deleteDownload(download);
- }
- }, Cu.reportError);
- }
+ document.l10n.get('main').formatValues(
+ 'delete-all-title', ['delete-all-message', { num: finished.length }]
+ ).then(([title, message]) => {
+ if (Services.prompt.confirm(null, title, message)) {
+ return Downloads
+ .getList(Downloads.ALL)
+ .then(list => {
+ for (let download of finished) {
+ list.remove(download).then(null, Cu.reportError);
+ deleteDownload(download);
+ }
+ }, Cu.reportError);
+ }
+ });
}
};
function DownloadItem(download) {
this._download = download;
this._updateFromDownload();
this._domain = DownloadUtils.getURIHost(download.source.url)[0];
@@ -294,19 +291,36 @@ DownloadItem.prototype = {
return element;
},
updateElement: function (element) {
element.querySelector(".date").textContent = this.startDate;
element.querySelector(".domain").textContent = this.domain;
element.querySelector(".icon").src = this.iconUrl;
- element.querySelector(".size").textContent = this.size;
- element.querySelector(".state").textContent = this.stateDescription;
element.querySelector(".title").setAttribute("value", this.fileName);
+
+ const size = this.size;
+ if (size === undefined) {
+ document.l10n.setAttributes(
+ element.querySelector(".size"),
+ 'download-size-unknown'
+ );
+ } else {
+ const elem = element.querySelector(".size");
+ if (elem.hasAttribute('data-l10n-id')) {
+ elem.removeAttribute('data-l10n-id');
+ }
+ elem.textContent = size;
+ }
+
+ document.l10n.setAttributes(
+ element.querySelector(".state"),
+ `download-state-${this.state}`
+ );
},
onClick: function (event) {
if (this.download.succeeded) {
this.download.launch().then(null, Cu.reportError);
}
},
@@ -330,44 +344,39 @@ DownloadItem.prototype = {
},
get size() {
if (this.download.succeeded && this.download.target.exists) {
return DownloadUtils.convertByteUnits(this.download.target.size).join("");
} else if (this.download.hasProgress) {
return DownloadUtils.convertByteUnits(this.download.totalBytes).join("");
}
- return strings.GetStringFromName("downloadState.unknownSize");
},
get startDate() {
return this._startDate;
},
- get stateDescription() {
- let name;
+ get state() {
if (this.download.error) {
- name = "downloadState.failed";
+ return "failed";
} else if (this.download.canceled) {
if (this.download.hasPartialData) {
- name = "downloadState.paused";
+ return "paused";
} else {
- name = "downloadState.canceled";
+ return "canceled";
}
} else if (!this.download.stopped) {
if (this.download.currentBytes > 0) {
- name = "downloadState.downloading";
+ return "downloading";
} else {
- name = "downloadState.starting";
+ return "starting";
}
}
- if (name) {
- return strings.GetStringFromName(name);
- }
- return "";
+ return "unknown";
}
};
window.addEventListener("DOMContentLoaded", event => {
contextMenu.init();
downloadLists.init()
-});
\ No newline at end of file
+});
--- a/mobile/android/chrome/content/aboutDownloads.xhtml
+++ b/mobile/android/chrome/content/aboutDownloads.xhtml
@@ -1,43 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" [
-<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
-%brandDTD;
-<!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd" >
-%globalDTD;
-<!ENTITY % downloadsDTD SYSTEM "chrome://browser/locale/aboutDownloads.dtd" >
-%downloadsDTD;
-]>
-
<!-- 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/. -->
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<head>
- <title>&aboutDownloads.title;</title>
+ <title data-l10n-id="title"></title>
<meta name="viewport" content="width=device-width; user-scalable=0" />
<link rel="icon" type="image/png" sizes="64x64" href="chrome://branding/content/favicon64.png" />
<link rel="stylesheet" href="chrome://browser/skin/aboutBase.css" type="text/css"/>
<link rel="stylesheet" href="chrome://browser/skin/aboutDownloads.css" type="text/css"/>
+
+ <link rel="localization" href="/mobile/aboutDownloads.ftl"/>
+ <script type="application/javascript" src="chrome://global/content/l20n-chrome-html.js"/>
</head>
-<body dir="&locale.dir;">
+<body>
<menu type="context" id="downloadmenu">
- <menuitem id="contextmenu-open" label="&aboutDownloads.open;"></menuitem>
- <menuitem id="contextmenu-retry" label="&aboutDownloads.retry;"></menuitem>
- <menuitem id="contextmenu-remove" label="&aboutDownloads.remove;"></menuitem>
- <menuitem id="contextmenu-pause" label="&aboutDownloads.pause;"></menuitem>
- <menuitem id="contextmenu-resume" label="&aboutDownloads.resume;"></menuitem>
- <menuitem id="contextmenu-cancel" label="&aboutDownloads.cancel;"></menuitem>
- <menuitem id="contextmenu-removeall" label="&aboutDownloads.removeAll;"></menuitem>
+ <menuitem id="contextmenu-open" data-l10n-id="open-menuitem"></menuitem>
+ <menuitem id="contextmenu-retry" data-l10n-id="retry-menuitem"></menuitem>
+ <menuitem id="contextmenu-remove" data-l10n-id="remove-menuitem"></menuitem>
+ <menuitem id="contextmenu-pause" data-l10n-id="pause-menuitem"></menuitem>
+ <menuitem id="contextmenu-resume" data-l10n-id="resume-menuitem"></menuitem>
+ <menuitem id="contextmenu-cancel" data-l10n-id="cancel-menuitem"></menuitem>
+ <menuitem id="contextmenu-removeall" data-l10n-id="remove-all-menuitem"></menuitem>
</menu>
<!--template id="download-item"-->
<li id="download-item" class="list-item" role="button" contextmenu="downloadmenu" style="display: none">
<img class="icon" src=""/>
<div class="details">
<div class="row">
<!-- This is a hack so that we can crop this label in its center -->
@@ -47,16 +40,16 @@
<div class="size"></div>
<div class="domain"></div>
<div class="state"></div>
</div>
</li>
<!--/template-->
<div class="header">
- <div>&aboutDownloads.header;</div>
+ <div data-l10n-id="header"></div>
</div>
<ul id="private-downloads-list" class="list"></ul>
<ul id="public-downloads-list" class="list"></ul>
- <span id="no-downloads-indicator">&aboutDownloads.empty;</span>
+ <span id="no-downloads-indicator" data-l10n-id="empty"></span>
<script type="application/javascript;version=1.8" src="chrome://browser/content/aboutDownloads.js"/>
</body>
</html>
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -20,16 +20,17 @@
@BINPATH@/chrome/@AB_CD@.manifest
@BINPATH@/@PREF_DIR@/mobile-l10n.js
@BINPATH@/update.locale
#ifdef MOZ_UPDATER
@BINPATH@/updater.ini
#endif
@BINPATH@/dictionaries/*
@BINPATH@/hyphenation/*
+@BINPATH@/localization/*
[assets destdir="assets/@ANDROID_CPU_ARCH@"]
#ifndef MOZ_STATIC_JS
@BINPATH@/@DLL_PREFIX@mozjs@DLL_SUFFIX@
#endif
#ifdef MOZ_DMD
@BINPATH@/@DLL_PREFIX@dmd@DLL_SUFFIX@
#endif
deleted file mode 100644
--- a/mobile/android/locales/en-US/chrome/aboutDownloads.dtd
+++ /dev/null
@@ -1,15 +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/. -->
-
-<!ENTITY aboutDownloads.title "Downloads">
-<!ENTITY aboutDownloads.header "Your Downloads">
-<!ENTITY aboutDownloads.empty "No Downloads">
-
-<!ENTITY aboutDownloads.open "Open">
-<!ENTITY aboutDownloads.remove "Delete">
-<!ENTITY aboutDownloads.removeAll "Delete All">
-<!ENTITY aboutDownloads.pause "Pause">
-<!ENTITY aboutDownloads.resume "Resume">
-<!ENTITY aboutDownloads.cancel "Cancel">
-<!ENTITY aboutDownloads.retry "Retry">
deleted file mode 100644
--- a/mobile/android/locales/en-US/chrome/aboutDownloads.properties
+++ /dev/null
@@ -1,17 +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 (downloadMessage.deleteAll):
-# Semicolon-separated list of plural forms. See:
-# http://developer.mozilla.org/en/docs/Localization_and_Plurals
-downloadMessage.deleteAll=Delete this download?;Delete #1 downloads?
-
-downloadAction.deleteAll=Delete All
-
-downloadState.downloading=Downloading…
-downloadState.canceled=Canceled
-downloadState.failed=Failed
-downloadState.paused=Paused
-downloadState.starting=Starting…
-downloadState.unknownSize=Unknown size
new file mode 100644
--- /dev/null
+++ b/mobile/android/locales/en-US/mobile/aboutDownloads.ftl
@@ -0,0 +1,37 @@
+# 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 = Downloads
+header = Your Downloads
+empty = No Downloads
+
+open-menuitem =
+ [html/label] Open
+retry-menuitem =
+ [html/label] Retry
+remove-menuitem =
+ [html/label] Delete
+pause-menuitem =
+ [html/label] Pause
+resume-menuitem =
+ [html/label] Resume
+cancel-menuitem =
+ [html/label] Cancel
+remove-all-menuitem =
+ [html/label] Delete All
+
+delete-all-title = Delete All
+delete-all-message = { $num ->
+ [1] Delete this download?
+ *[other] Delete { $num } downloads?
+}
+
+download-state-downloading = Downloading…
+download-state-canceled = Canceled
+download-state-failed = Failed
+download-state-paused = Paused
+download-state-starting = Starting…
+download-state-unknown = Unknown
+
+download-size-unknown = Unknown size
--- a/mobile/android/locales/jar.mn
+++ b/mobile/android/locales/jar.mn
@@ -1,24 +1,24 @@
#filter substitution
# 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] @AB_CD@.jar:
+ mobile (%mobile/**/*.ftl)
@AB_CD@.jar:
% locale browser @AB_CD@ %locale/@AB_CD@/browser/
locale/@AB_CD@/browser/about.dtd (%chrome/about.dtd)
locale/@AB_CD@/browser/aboutAccounts.dtd (%chrome/aboutAccounts.dtd)
locale/@AB_CD@/browser/aboutAccounts.properties (%chrome/aboutAccounts.properties)
locale/@AB_CD@/browser/aboutAddons.dtd (%chrome/aboutAddons.dtd)
locale/@AB_CD@/browser/aboutAddons.properties (%chrome/aboutAddons.properties)
locale/@AB_CD@/browser/aboutCertError.dtd (%chrome/aboutCertError.dtd)
- locale/@AB_CD@/browser/aboutDownloads.dtd (%chrome/aboutDownloads.dtd)
- locale/@AB_CD@/browser/aboutDownloads.properties (%chrome/aboutDownloads.properties)
locale/@AB_CD@/browser/aboutHome.dtd (%chrome/aboutHome.dtd)
locale/@AB_CD@/browser/aboutHome.properties (%chrome/aboutHome.properties)
locale/@AB_CD@/browser/aboutPrivateBrowsing.dtd (%chrome/aboutPrivateBrowsing.dtd)
#ifdef MOZ_SERVICES_HEALTHREPORT
locale/@AB_CD@/browser/aboutHealthReport.dtd (%chrome/aboutHealthReport.dtd)
#endif
locale/@AB_CD@/browser/browser.properties (%chrome/browser.properties)
locale/@AB_CD@/browser/config.dtd (%chrome/config.dtd)