From 9f4745fd3fb7e49c033b7c9468e4623813095888 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Sun, 15 Sep 2013 15:27:52 +0200 Subject: [PATCH] webL10n: Apply PDF.js-specific changes Based on http://pastebin.mozilla.org/3061694 1. Remove "debug helpers" and use console.log/console.warn directly (top). 2. Remove page load initialization (middle). 3. Remove window._ alias (bottom) The original diff contained an extra entry "Adds fallback argument to the getL10nData;", but this was already implemented in the rebased webL10n, so it's no longer PDF.js-specific. --- external/webL10n/l10n.js | 200 ++++----------------------------------- 1 file changed, 16 insertions(+), 184 deletions(-) diff --git a/external/webL10n/l10n.js b/external/webL10n/l10n.js index 1c4ab6a93..f13c8d60b 100644 --- a/external/webL10n/l10n.js +++ b/external/webL10n/l10n.js @@ -19,6 +19,12 @@ * 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 consoleWarn and consoleLog and use console.log/warn directly. + - Removes window._ assignment. +*/ /*jshint browser: true, devel: true, es5: true, globalstrict: true */ 'use strict'; @@ -47,29 +53,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 +85,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 +101,7 @@ document.webL10n = (function(window, document, undefined) { function xhrLoadText(url, onSuccess, onFailure, asynchronous) { onSuccess = onSuccess || function _onSuccess(data) {}; onFailure = onFailure || function _onFailure() { - consoleWarn(url + ' not found.'); + console.warn(url + ' not found.'); }; var xhr = new XMLHttpRequest(); @@ -298,11 +281,11 @@ 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] || dict.locales[dict.default_locale]; callback(); } else { - consoleLog('no resource to load, early way out'); + console.log('no resource to load, early way out'); } // early way out fireL10nReadyEvent(lang); @@ -329,7 +312,7 @@ document.webL10n = (function(window, document, undefined) { this.load = function(lang, callback) { var applied = lang; parseResource(href, lang, callback, function() { - consoleWarn(href + ' not found.'); + console.warn(href + ' not found.'); applied = ''; }); return applied; // return lang if found, an empty string if not found @@ -340,7 +323,7 @@ document.webL10n = (function(window, document, undefined) { var resource = new L10nResourceLink(langLinks[i]); var rv = resource.load(lang, onResourceLoaded); if (rv != lang) { // lang not found, used default resource instead - consoleWarn('"' + lang + '" resource not found'); + console.warn('"' + lang + '" resource not found'); gLanguage = ''; } } @@ -761,7 +744,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]; @@ -808,7 +791,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; } @@ -871,7 +854,7 @@ document.webL10n = (function(window, document, undefined) { } else if (arg in gL10nData) { sub = gL10nData[arg][gTextProp]; } else { - consoleLog('argument {{' + arg + '}} for #' + key + ' is undefined.'); + console.log('argument {{' + arg + '}} for #' + key + ' is undefined.'); return str; } @@ -891,7 +874,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; } @@ -959,151 +942,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