Skip to content

Commit

Permalink
Merge pull request #4508 from Snuffleupagus/extension-firefox-braces
Browse files Browse the repository at this point in the history
Fix coding style in extensions/firefox
  • Loading branch information
timvandermeij committed Mar 22, 2014
2 parents 8355b51 + 2b5fb59 commit 46f0160
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
9 changes: 6 additions & 3 deletions extensions/firefox/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ function setStringPref(pref, value) {
}

function log(str) {
if (!getBoolPref(EXT_PREFIX + '.pdfBugEnabled', false))
if (!getBoolPref(EXT_PREFIX + '.pdfBugEnabled', false)) {
return;
}
dump(str + '\n');
}

Expand Down Expand Up @@ -101,8 +102,9 @@ Factory.prototype = {

// nsIFactory
createInstance: function createInstance(aOuter, iid) {
if (aOuter !== null)
if (aOuter !== null) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
return (new (this._targetConstructor)()).QueryInterface(iid);
},

Expand Down Expand Up @@ -150,8 +152,9 @@ function startup(aData, aReason) {
}

function shutdown(aData, aReason) {
if (aReason == APP_SHUTDOWN)
if (aReason == APP_SHUTDOWN) {
return;
}
var ioService = Services.io;
var resProt = ioService.getProtocolHandler('resource')
.QueryInterface(Ci.nsIResProtocolHandler);
Expand Down
40 changes: 25 additions & 15 deletions extensions/firefox/tools/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
function getL10nData(key) {
var response = FirefoxCom.requestSync('getStrings', key);
var data = JSON.parse(response);
if (!data)
if (!data) {
console.warn('[l10n] #' + key + ' missing for [' + gLanguage + ']');
}
return data;
}

// replace {{arguments}} with their values
function substArguments(text, args) {
if (!args)
if (!args) {
return text;

}
return text.replace(/\{\{\s*(\w+)\s*\}\}/g, function(all, name) {
return name in args ? args[name] : '{{' + name + '}}';
return (name in args ? args[name] : '{{' + name + '}}');
});
}

Expand All @@ -48,28 +49,33 @@

// translate an HTML element
function translateElement(element) {
if (!element || !element.dataset)
if (!element || !element.dataset) {
return;
}

// get the related l10n object
var key = element.dataset.l10nId;
var data = getL10nData(key);
if (!data)
if (!data) {
return;
}

// get arguments (if any)
// TODO: more flexible parser?
var args;
if (element.dataset.l10nArgs) try {
args = JSON.parse(element.dataset.l10nArgs);
} catch (e) {
console.warn('[l10n] could not parse arguments for #' + key + '');
if (element.dataset.l10nArgs) {
try {
args = JSON.parse(element.dataset.l10nArgs);
} catch (e) {
console.warn('[l10n] could not parse arguments for #' + key + '');
}
}

// translate element
// TODO: security check?
for (var k in data)
for (var k in data) {
element[k] = substArguments(data[k], args);
}
}


Expand All @@ -80,12 +86,14 @@
// check all translatable children (= w/ a `data-l10n-id' attribute)
var children = element.querySelectorAll('*[data-l10n-id]');
var elementCount = children.length;
for (var i = 0; i < elementCount; i++)
for (var i = 0; i < elementCount; i++) {
translateElement(children[i]);
}

// translate element itself if necessary
if (element.dataset.l10nId)
if (element.dataset.l10nId) {
translateElement(element);
}
}

window.addEventListener('DOMContentLoaded', function() {
Expand All @@ -106,14 +114,16 @@
get: translateString,

// get the document language
getLanguage: function() { return gLanguage; },
getLanguage: function() {
return gLanguage;
},

// get the direction (ltr|rtl) of the current language
getDirection: function() {
// http://www.w3.org/International/questions/qa-scripts
// Arabic, Hebrew, Farsi, Pashto, Urdu
var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
return (rtlList.indexOf(gLanguage) >= 0) ? 'rtl' : 'ltr';
return (rtlList.indexOf(gLanguage) >= 0 ? 'rtl' : 'ltr');
},

// translate an element or document fragment
Expand Down

0 comments on commit 46f0160

Please sign in to comment.