Skip to content

Commit

Permalink
De-XBL-ify l20n-chrome-*
Browse files Browse the repository at this point in the history
Before this patch XUL and XBL were localized via a localization.xml binding.
Now XUL files are localized using the same API as HTML (<link> elements) and
XBL bindings rae localized by calling a special API from the <constructor>.
  • Loading branch information
stasm committed Jul 12, 2016
1 parent 001a0c5 commit 706b970
Show file tree
Hide file tree
Showing 16 changed files with 833 additions and 114 deletions.
4 changes: 0 additions & 4 deletions browser/base/content/aboutDialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
line-height: 1.5;
}

localization {
-moz-binding: url("chrome://global/content/bindings/localization.xml#xul");
}

#rightBox {
background-image: url("chrome://branding/content/about-wordmark.svg");
background-repeat: no-repeat;
Expand Down
8 changes: 3 additions & 5 deletions browser/base/content/aboutDialog.xul
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
#ifdef MOZ_UPDATER
<script type="application/javascript" src="chrome://browser/content/aboutDialog-appUpdater.js"/>
#endif
<script type="application/javascript" src="chrome://global/content/l20n-chrome-observer.js"/>

<localization>
<source src="/branding/brand.ftl"/>
<source src="/browser/aboutDialog.ftl"/>
</localization>
<link rel="localization" href="/branding/brand.ftl" />
<link rel="localization" href="/browser/aboutDialog.ftl" />
<script type="application/javascript" src="chrome://global/content/l20n-chrome-xul.js"/>

<vbox id="aboutDialogContainer">
<hbox id="clientBox">
Expand Down
4 changes: 0 additions & 4 deletions browser/base/content/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
min-width: -moz-fit-content;
}

localization {
-moz-binding: url("chrome://global/content/bindings/localization.xml#xul");
}

searchbar {
-moz-binding: url("chrome://browser/content/search/search.xml#searchbar");
}
Expand Down
7 changes: 2 additions & 5 deletions browser/base/content/browser.xul
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@
<script type="application/javascript" src="chrome://browser/content/downloads/indicator.js"/>
<script type="application/javascript" src="chrome://browser/content/places/editBookmarkOverlay.js"/>

<script type="application/javascript" src="chrome://global/content/l20n-chrome-observer.js"/>

<localization>
<source src="/browser/browser.ftl"/>
</localization>
<link rel="localization" href="/browser/browser.ftl"/>
<script type="application/javascript" src="chrome://global/content/l20n-chrome-xul.js"/>

# All sets except for popupsets (commands, keys, stringbundles and broadcasters) *must* go into the
# browser-sets.inc file for sharing with hiddenWindow.xul.
Expand Down
4 changes: 0 additions & 4 deletions browser/base/content/tabbrowser.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
-moz-binding: url("chrome://browser/content/tabbrowser.xml#tabbrowser-close-tab-button");
}

localization {
-moz-binding: url("chrome://global/content/bindings/localization.xml#xul");
}

.tab-close-button[pinned],
.tabbrowser-tabs[closebuttons="activetab"] > * > * > * > .tab-close-button:not([visuallyselected="true"]),
.tab-icon-image:not([src]):not([pinned]):not([crashed])[selected],
Expand Down
15 changes: 12 additions & 3 deletions browser/base/content/tabbrowser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4901,9 +4901,6 @@
</resources>

<content>
<xul:localization name="tabbrowser-l10n">
<xul:source src="/browser/tabbrowser.ftl"/>
</xul:localization>
<xul:hbox align="end">
<xul:image class="tab-drop-indicator" anonid="tab-drop-indicator" collapsed="true"/>
</xul:hbox>
Expand Down Expand Up @@ -4952,9 +4949,21 @@
this._tabAnimationLoggingEnabled = false;
}
this._browserNewtabpageEnabled = Services.prefs.getBoolPref("browser.newtabpage.enabled");
Components.utils.import("chrome://global/content/l20n-chrome-xbl.js");
createLocalization("tabbrowser-l10n", [
"/browser/tabbrowser.ftl"
], this, document.l10n);
]]>
</constructor>

<destructor>
<![CDATA[
document.l10n.disconnectRoot(this);
]]>
</destructor>

<field name="tabbrowser" readonly="true">
document.getElementById(this.getAttribute("tabbrowser"));
</field>
Expand Down
2 changes: 1 addition & 1 deletion browser/locales/en-US/chrome/browser/browser.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ can reach it easily. -->

<!ENTITY listAllTabs.label "List all tabs">

<!ENTITY tabCmd.label "New Tab">
<!ENTITY tabCmd.label "New Tab (dtd)">
<!ENTITY tabCmd.accesskey "T">
<!ENTITY tabCmd.commandkey "t">
<!-- LOCALIZATION NOTE (openLocationCmd.label): "Open Location" is only
Expand Down
2 changes: 1 addition & 1 deletion browser/locales/en-US/chrome/browser/newTab.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!-- These strings are used in the about:newtab page -->
<!ENTITY newtab.pageTitle "New Tab">
<!ENTITY newtab.pageTitle "New Tab (about:newtab)">
<!ENTITY newtab.customize.classic "Show your top sites">
<!ENTITY newtab.customize.cog.enhanced "Include suggested sites">
<!ENTITY newtab.customize.cog.title2 "NEW TAB CONTROLS">
Expand Down
2 changes: 1 addition & 1 deletion browser/locales/en-US/chrome/browser/tabbrowser.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tabs.loading=Loading…
tabs.waiting=Waiting…
tabs.downloading=Downloading…

tabs.emptyTabTitle=New Tab
tabs.emptyTabTitle=New Tab (properties)
tabs.closeTab=Close Tab
tabs.close=Close
tabs.closeWarningTitle=Confirm close
Expand Down
4 changes: 2 additions & 2 deletions toolkit/content/jar.mn
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ toolkit.jar:
content/global/nsDragAndDrop.js
content/global/process-content.js
content/global/l20n-chrome-html.js
content/global/l20n-chrome-observer.js
content/global/l20n-chrome-xbl.js
content/global/l20n-chrome-xul.js
content/global/l20n-content-html.js
content/global/resetProfile.css
content/global/resetProfile.js
Expand All @@ -89,7 +90,6 @@ toolkit.jar:
content/global/bindings/general.xml (widgets/general.xml)
content/global/bindings/groupbox.xml (widgets/groupbox.xml)
content/global/bindings/listbox.xml (widgets/listbox.xml)
content/global/bindings/localization.xml (widgets/localization.xml)
content/global/bindings/menu.xml (widgets/menu.xml)
content/global/bindings/menulist.xml (widgets/menulist.xml)
content/global/bindings/notification.xml (widgets/notification.xml)
Expand Down
4 changes: 2 additions & 2 deletions toolkit/content/l20n-chrome-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ class Localization {
return translations.map(tuple => tuple[0]);
}

if (console) {
errors.forEach(e => console.warn(e)); // eslint-disable-line no-console
if (typeof console !== 'undefined') {
errors.forEach(console.warn); // eslint-disable-line no-console
}

const { createContext } = properties.get(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
/* 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/. */
'use strict';
{

class L10nError extends Error {
constructor(message, id, lang) {
Expand Down Expand Up @@ -107,8 +103,8 @@ class Localization {
return translations.map(tuple => tuple[0]);
}

if (console) {
errors.forEach(e => console.warn(e)); // eslint-disable-line no-console
if (typeof console !== 'undefined') {
errors.forEach(console.warn); // eslint-disable-line no-console
}

const { createContext } = properties.get(this);
Expand Down Expand Up @@ -415,7 +411,7 @@ function createObserve(obs) {
}
}

this.EXPORTED_SYMBOLS = ['createXULLocalization', 'ChromeResourceBundle'];
this.EXPORTED_SYMBOLS = ['createLocalization'];

Components.utils.import('resource://gre/modules/Services.jsm');
Components.utils.import('resource://gre/modules/L10nRegistry.jsm');
Expand All @@ -442,12 +438,34 @@ function createContext(lang) {
return new MessageContext(lang, { functions });
}

this.createXULLocalization = function(obs, requestBundles) {
const l10n = new XULLocalization(requestBundles, createContext);
l10n.observe = createObserve(obs);
Services.obs.addObserver(l10n, 'language-registry-update', false);
Services.obs.addObserver(l10n, 'language-registry-incremental', false);
return l10n;
function getRequestedLangs() {
return Services.prefs.getComplexValue(
'intl.accept_languages', Components.interfaces.nsIPrefLocalizedString
).data.split(',').map(String.trim);
}

this.ChromeResourceBundle = ChromeResourceBundle;
function createLocalization(name, resIds, host, obs) {
if (!obs.has(name)) {
function requestBundles(requestedLangs = getRequestedLangs()) {
return L10nRegistry.getResources(requestedLangs, resIds).then(
({bundles}) => bundles.map(
bundle => new ChromeResourceBundle(bundle.locale, bundle.resources)
)
);
}

const l10n = new XULLocalization(requestBundles, createContext);
l10n.observe = createObserve(obs);
Services.obs.addObserver(l10n, 'language-registry-update', false);
Services.obs.addObserver(l10n, 'language-registry-incremental', false);

obs.set(name, l10n);
}

obs.observeRoot(host, obs.get(name));
obs.translateRoot(host);
}

this.createLocalization = createLocalization;

}
Loading

0 comments on commit 706b970

Please sign in to comment.