Bug 1314861: Lazily initialize l10n code. r=rpl

MozReview-Commit-ID: DgmrEMQGrtw

--HG--
extra : rebase_source : 0017656c28df95d00f9d2990fd8e06964662a66c
This commit is contained in:
Kris Maglione 2016-10-30 16:53:37 -07:00
Родитель f8c1ebdfda
Коммит 1ed499730b
6 изменённых файлов: 33 добавлений и 21 удалений

Просмотреть файл

@ -8,9 +8,10 @@ module.metadata = {
};
const { Ci, Cc, Cu } = require("chrome");
const core = require("../l10n/core");
const { loadSheet, removeSheet } = require("../stylesheet/utils");
lazyRequireModule(this, "../l10n/core", "core");
lazyRequire(this, "../stylesheet/utils", "loadSheet", "removeSheet");
const { process, frames } = require("../remote/child");
var observerService = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
const { ShimWaiver } = Cu.import("resource://gre/modules/ShimWaiver.jsm");

Просмотреть файл

@ -7,14 +7,17 @@ module.metadata = {
"stability": "stable"
};
const json = require("./l10n/json/core");
const { get: getKey } = require("./l10n/core");
const properties = require("./l10n/properties/core");
const { getRulesForLocale } = require("./l10n/plural-rules");
lazyRequireModule(this, "./l10n/json/core", "json");
lazyRequire(this, "./l10n/core", {"get": "getKey"});
lazyRequireModule(this, "./l10n/properties/core", "properties");
lazyRequire(this, "./l10n/plural-rules", "getRulesForLocale");
const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
// Retrieve the plural mapping function
var pluralMappingFunction = getRulesForLocale(json.language()) ||
getRulesForLocale("en");
XPCOMUtils.defineLazyGetter(this, "pluralMappingFunction",
() => getRulesForLocale(json.language()) ||
getRulesForLocale("en"));
exports.get = function get(k) {
// For now, we only accept a "string" as first argument

Просмотреть файл

@ -3,7 +3,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const json = require("./json/core");
const properties = require("./properties/core");
lazyRequireModule(this, "./json/core", "json");
lazyRequireModule(this, "./properties/core", "properties");
exports.get = json.usingJSON ? json.get : properties.get;
const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyGetter(this, "get",
() => json.usingJSON ? json.get : properties.get);
module.exports = Object.freeze({
get get() { return get; }, // ... yeah.
});

Просмотреть файл

@ -8,9 +8,9 @@ module.metadata = {
};
const { Cc, Ci } = require("chrome");
const { getPreferedLocales, findClosestLocale } = require("./locale");
const { readURI } = require("../net/url");
const { resolve } = require("../core/promise");
lazyRequire(this, "./locale", "getPreferedLocales", "findClosestLocale");
lazyRequire(this, "../net/url", "readURI");
lazyRequire(this, "../core/promise", "resolve");
function parseJsonURI(uri) {
return readURI(uri).

Просмотреть файл

@ -3,8 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { on } = require("../system/events");
const core = require("./core");
lazyRequire(this, "../system/events", "on");
lazyRequireModule(this, "./core", "core");
const { id: jetpackId } = require('../self');
const OPTIONS_DISPLAYED = "addon-options-displayed";

Просмотреть файл

@ -4,14 +4,16 @@
"use strict";
const { Cu } = require("chrome");
const { newURI } = require('../../url/utils')
const { getRulesForLocale } = require("../plural-rules");
const { getPreferedLocales } = require('../locale');
lazyRequire(this, '../../url/utils', 'newURI');
lazyRequire(this, "../plural-rules", 'getRulesForLocale');
lazyRequire(this, '../locale', 'getPreferedLocales');
const { rootURI } = require("@loader/options");
const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
const { Services } = require("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
const baseURI = rootURI + "locale/";
const preferedLocales = getPreferedLocales(true);
XPCOMUtils.defineLazyGetter(this, "preferedLocales", () => getPreferedLocales(true));
// Make sure we don't get stale data after an update
// (See Bug 1300735 for rationale).