From 537216b872cab481d6d2eb620ad0e43a25c2e992 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Tue, 10 Mar 2015 16:09:26 +0100 Subject: [PATCH] [webL10n] Apply PDF.js-specific changes --- external/webL10n/l10n.js | 209 ++++----------------------------------- 1 file changed, 17 insertions(+), 192 deletions(-) diff --git a/external/webL10n/l10n.js b/external/webL10n/l10n.js index 9c4656409..533fab6f8 100644 --- a/external/webL10n/l10n.js +++ b/external/webL10n/l10n.js @@ -19,6 +19,13 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ +/* + Additional modifications for PDF.js project: + - Disables language initialization on page loading; + - Removes console.warn and console.log and use console.log/warn directly. + - Removes window._ assignment. + - Remove compatibility code for OldIE. +*/ /*jshint browser: true, devel: true, es5: true, globalstrict: true */ 'use strict'; @@ -47,29 +54,6 @@ document.webL10n = (function(window, document, undefined) { var gAsyncResourceLoading = true; // read-only - /** - * Debug helpers - * - * gDEBUG == 0: don't display any console message - * gDEBUG == 1: display only warnings, not logs - * gDEBUG == 2: display all console messages - */ - - var gDEBUG = 1; - - function consoleLog(message) { - if (gDEBUG >= 2) { - console.log('[l10n] ' + message); - } - } - - function consoleWarn(message) { - if (gDEBUG) { - console.warn('[l10n] ' + message); - } - } - - /** * DOM helpers for the so-called "HTML API". * @@ -102,7 +86,7 @@ document.webL10n = (function(window, document, undefined) { try { args = JSON.parse(l10nArgs); } catch (e) { - consoleWarn('could not parse arguments for #' + l10nId); + console.warn('could not parse arguments for #' + l10nId); } } return { id: l10nId, args: args }; @@ -118,7 +102,7 @@ document.webL10n = (function(window, document, undefined) { function xhrLoadText(url, onSuccess, onFailure) { onSuccess = onSuccess || function _onSuccess(data) {}; onFailure = onFailure || function _onFailure() { - consoleWarn(url + ' not found.'); + console.warn(url + ' not found.'); }; var xhr = new XMLHttpRequest(); @@ -321,7 +305,7 @@ document.webL10n = (function(window, document, undefined) { // we might have a pre-compiled dictionary instead var dict = getL10nDictionary(); if (dict && dict.locales && dict.default_locale) { - consoleLog('using the embedded JSON directory, early way out'); + console.log('using the embedded JSON directory, early way out'); gL10nData = dict.locales[lang]; if (!gL10nData) { var defaultLocale = dict.default_locale.toLowerCase(); @@ -337,7 +321,7 @@ document.webL10n = (function(window, document, undefined) { } callback(); } else { - consoleLog('no resource to load, early way out'); + console.log('no resource to load, early way out'); } // early way out fireL10nReadyEvent(lang); @@ -364,9 +348,9 @@ document.webL10n = (function(window, document, undefined) { // are synchronously called. this.load = function(lang, callback) { parseResource(href, lang, callback, function() { - consoleWarn(href + ' not found.'); + console.warn(href + ' not found.'); // lang not found, used default resource instead - consoleWarn('"' + lang + '" resource not found'); + console.warn('"' + lang + '" resource not found'); gLanguage = ''; // Resource not loaded, but we still need to call the callback. callback(); @@ -795,7 +779,7 @@ document.webL10n = (function(window, document, undefined) { // return a function that gives the plural form name for a given integer var index = locales2rules[lang.replace(/-.*$/, '')]; if (!(index in pluralRules)) { - consoleWarn('plural form unknown for [' + lang + ']'); + console.warn('plural form unknown for [' + lang + ']'); return function() { return 'other'; }; } return pluralRules[index]; @@ -842,7 +826,7 @@ document.webL10n = (function(window, document, undefined) { function getL10nData(key, args, fallback) { var data = gL10nData[key]; if (!data) { - consoleWarn('#' + key + ' is undefined.'); + console.warn('#' + key + ' is undefined.'); if (!fallback) { return null; } @@ -900,7 +884,7 @@ document.webL10n = (function(window, document, undefined) { if (arg in gL10nData) { return gL10nData[arg]; } - consoleLog('argument {{' + arg + '}} for #' + key + ' is undefined.'); + console.log('argument {{' + arg + '}} for #' + key + ' is undefined.'); return matched_text; }); } @@ -914,7 +898,7 @@ document.webL10n = (function(window, document, undefined) { // get the related l10n object var data = getL10nData(l10n.id, l10n.args); if (!data) { - consoleWarn('#' + l10n.id + ' is undefined.'); + console.warn('#' + l10n.id + ' is undefined.'); return; } @@ -982,152 +966,6 @@ document.webL10n = (function(window, document, undefined) { translateElement(element); } - - /** - * Startup & Public API - * - * Warning: this part of the code contains browser-specific chunks -- - * that's where obsolete browsers, namely IE8 and earlier, are handled. - * - * Unlike the rest of the lib, this section is not shared with FirefoxOS/Gaia. - */ - - // load the default locale on startup - function l10nStartup() { - gReadyState = 'interactive'; - - // most browsers expose the UI language as `navigator.language' - // but IE uses `navigator.userLanguage' instead - var userLocale = navigator.language || navigator.userLanguage; - consoleLog('loading [' + userLocale + '] resources, ' + - (gAsyncResourceLoading ? 'asynchronously.' : 'synchronously.')); - - // load the default locale and translate the document if required - if (document.documentElement.lang === userLocale) { - loadLocale(userLocale); - } else { - loadLocale(userLocale, translateFragment); - } - } - - // browser-specific startup - if (document.addEventListener) { // modern browsers and IE9+ - if (document.readyState === 'loading') { - // the document is not fully loaded yet: wait for DOMContentLoaded. - document.addEventListener('DOMContentLoaded', l10nStartup); - } else { - // l10n.js is being loaded with