Merge pull request #1783 from simong/removed-console-in-html10n
Removed console wrapping in html10n as it's breaking in PhantomJS.pull/2114/merge
commit
135aa3e8fe
|
@ -23,28 +23,16 @@
|
||||||
window.html10n = (function(window, document, undefined) {
|
window.html10n = (function(window, document, undefined) {
|
||||||
|
|
||||||
// fix console
|
// fix console
|
||||||
var console = window.console
|
(function() {
|
||||||
function interceptConsole(method){
|
var noop = function() {};
|
||||||
if (!console) return function() {}
|
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
|
||||||
|
var console = (window.console = window.console || {});
|
||||||
var original = console[method]
|
for (var i = 0; i < names.length; ++i) {
|
||||||
|
if (!console[names[i]]) {
|
||||||
// do sneaky stuff
|
console[names[i]] = noop;
|
||||||
if (original.bind){
|
|
||||||
// Do this for normal browsers
|
|
||||||
return original.bind(console)
|
|
||||||
}else{
|
|
||||||
return function() {
|
|
||||||
// Do this for IE
|
|
||||||
var message = Array.prototype.slice.apply(arguments).join(' ')
|
|
||||||
original(message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var consoleLog = interceptConsole('log')
|
}());
|
||||||
, consoleWarn = interceptConsole('warn')
|
|
||||||
, consoleError = interceptConsole('warn')
|
|
||||||
|
|
||||||
|
|
||||||
// fix Array#forEach in IE
|
// fix Array#forEach in IE
|
||||||
// taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
|
// taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
|
||||||
|
@ -148,7 +136,7 @@ window.html10n = (function(window, document, undefined) {
|
||||||
for (var i=0, n=this.resources.length; i < n; i++) {
|
for (var i=0, n=this.resources.length; i < n; i++) {
|
||||||
this.fetch(this.resources[i], lang, function(e) {
|
this.fetch(this.resources[i], lang, function(e) {
|
||||||
reqs++;
|
reqs++;
|
||||||
if(e) consoleWarn(e)
|
if(e) console.warn(e)
|
||||||
|
|
||||||
if (reqs < n) return;// Call back once all reqs are completed
|
if (reqs < n) return;// Call back once all reqs are completed
|
||||||
cb && cb()
|
cb && cb()
|
||||||
|
@ -647,7 +635,7 @@ window.html10n = (function(window, document, undefined) {
|
||||||
// return a function that gives the plural form name for a given integer
|
// return a function that gives the plural form name for a given integer
|
||||||
var index = locales2rules[lang.replace(/-.*$/, '')];
|
var index = locales2rules[lang.replace(/-.*$/, '')];
|
||||||
if (!(index in pluralRules)) {
|
if (!(index in pluralRules)) {
|
||||||
consoleWarn('plural form unknown for [' + lang + ']');
|
console.warn('plural form unknown for [' + lang + ']');
|
||||||
return function() { return 'other'; };
|
return function() { return 'other'; };
|
||||||
}
|
}
|
||||||
return pluralRules[index];
|
return pluralRules[index];
|
||||||
|
@ -727,7 +715,7 @@ window.html10n = (function(window, document, undefined) {
|
||||||
var i = 0
|
var i = 0
|
||||||
, n = list.length
|
, n = list.length
|
||||||
iterator(list[i], i, function each(err) {
|
iterator(list[i], i, function each(err) {
|
||||||
if(err) consoleLog(err)
|
if(err) console.error(err)
|
||||||
i++
|
i++
|
||||||
if (i < n) return iterator(list[i],i, each);
|
if (i < n) return iterator(list[i],i, each);
|
||||||
cb()
|
cb()
|
||||||
|
@ -750,8 +738,8 @@ window.html10n = (function(window, document, undefined) {
|
||||||
|
|
||||||
html10n.get = function(id, args) {
|
html10n.get = function(id, args) {
|
||||||
var translations = html10n.translations
|
var translations = html10n.translations
|
||||||
if(!translations) return consoleWarn('No translations available (yet)')
|
if(!translations) return console.warn('No translations available (yet)')
|
||||||
if(!translations[id]) return consoleWarn('Could not find string '+id)
|
if(!translations[id]) return console.warn('Could not find string '+id)
|
||||||
|
|
||||||
// apply macros
|
// apply macros
|
||||||
var str = translations[id]
|
var str = translations[id]
|
||||||
|
@ -781,7 +769,7 @@ window.html10n = (function(window, document, undefined) {
|
||||||
} else if (arg in translations) {
|
} else if (arg in translations) {
|
||||||
sub = translations[arg]
|
sub = translations[arg]
|
||||||
} else {
|
} else {
|
||||||
consoleWarn('Could not find argument {{' + arg + '}}')
|
console.warn('Could not find argument {{' + arg + '}}')
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -840,7 +828,7 @@ window.html10n = (function(window, document, undefined) {
|
||||||
str.id = node.getAttribute('data-l10n-id')
|
str.id = node.getAttribute('data-l10n-id')
|
||||||
if (!str.id) return
|
if (!str.id) return
|
||||||
|
|
||||||
if(!translations[str.id]) return consoleWarn('Couldn\'t find translation key '+str.id)
|
if(!translations[str.id]) return console.warn('Couldn\'t find translation key '+str.id)
|
||||||
|
|
||||||
// get args
|
// get args
|
||||||
if(window.JSON) {
|
if(window.JSON) {
|
||||||
|
@ -849,7 +837,7 @@ window.html10n = (function(window, document, undefined) {
|
||||||
try{
|
try{
|
||||||
str.args = eval(node.getAttribute('data-l10n-args'))
|
str.args = eval(node.getAttribute('data-l10n-args'))
|
||||||
}catch(e) {
|
}catch(e) {
|
||||||
consoleWarn('Couldn\'t parse args for '+str.id)
|
console.warn('Couldn\'t parse args for '+str.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,7 +875,7 @@ window.html10n = (function(window, document, undefined) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
consoleWarn('Unexpected error: could not translate element content for key '+str.id, node)
|
console.warn('Unexpected error: could not translate element content for key '+str.id, node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue