Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bug 855524 - Localize lazy loaded contents #9035

Merged
merged 1 commit into from

3 participants

@fabi1cazenave
Collaborator

I’m not familiar with the Browser code base but this patch worries me a bit:

  • (nitpick) the braces are missing for the if statement.
  • mozL10n.translate() works on DOM elements only — I’m not sure what “file” is in this context, maybe it’s just a misleading variable name?
  • does your code make sure that mozL10n is ready before getting in there? You should probably rely on mozL10n.ready(callback) or check the mozL10n.readyState property.
apps/browser/js/browser.js
@@ -154,6 +156,19 @@ var Browser = {
var loadBrowserFiles = function() {
LazyLoader.load(jsFiles, function() {
+ var mozL10n = navigator.mozL10n;
+ var localizeElements = function browser_localizeElements() {
+ elementsToLoad.forEach(function l10nElement(element) {
+ mozL10n.translate(element);
+ });
+ };
+
+ if (mozL10n.readyState === 'complete') {
+ localizeElements();
+ } else {
+ mozL10n.ready(localizeElements);
+ }
+
@fabi1cazenave Collaborator

if you use mozL10n.ready(), you don’t need to check the readyState property. This would be fine:

var mozL10n = navigator.mozL10n;
mozL10n.ready(function browser_localizeElements() {
  elementsToLoad.forEach(function l10nElement(element) {
    mozL10n.translate(element);
  });
});

Thanks for the filesToLoad / elementsToLoad separation, it’s very clear now. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@benfrancis benfrancis merged commit 2d48fb6 into mozilla-b2g:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 11, 2013
  1. @crh0716
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 3 deletions.
  1. +13 −3 apps/browser/js/browser.js
View
16 apps/browser/js/browser.js
@@ -105,7 +105,7 @@ var Browser = {
return;
console.log('----------loadink!');
- var filesToLoad = [
+ var elementsToLoad = [
// DOM Nodes with commented content to load
this.awesomescreen,
this.crashscreen,
@@ -117,8 +117,10 @@ var Browser = {
document.getElementById('modal-dialog-prompt'),
document.getElementById('modal-dialog-confirm'),
document.getElementById('modal-dialog-custom-prompt'),
- document.getElementById('http-authentication-dialog'),
+ document.getElementById('http-authentication-dialog')
+ ];
+ var filesToLoad = [
// css files
'shared/style/headers.css',
'shared/style/buttons.css',
@@ -154,6 +156,13 @@ var Browser = {
var loadBrowserFiles = function() {
LazyLoader.load(jsFiles, function() {
+ var mozL10n = navigator.mozL10n;
+ mozL10n.ready(function browser_localizeElements() {
+ elementsToLoad.forEach(function l10nElement(element) {
+ mozL10n.translate(element);
+ });
+ });
+
domElements.forEach(function createElementRef(name) {
this[this.toCamelCase(name)] = document.getElementById(name);
}, this);
@@ -166,7 +175,8 @@ var Browser = {
}.bind(this));
};
- LazyLoader.load(filesToLoad, loadBrowserFiles.bind(this));
+ LazyLoader.load(elementsToLoad.concat(filesToLoad),
+ loadBrowserFiles.bind(this));
},
initRemainingListeners: function browser_initRemainingListeners() {
Something went wrong with that request. Please try again.