mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1190323: Part 1 - [webext] Fix @@extension_id locale string substitutions. r=billm
This commit is contained in:
parent
8e8e10a1d7
commit
779504a2f6
@ -426,6 +426,8 @@ this.ExtensionData = function(rootURI) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ExtensionData.prototype = {
|
ExtensionData.prototype = {
|
||||||
|
builtinMessages: null,
|
||||||
|
|
||||||
get logger() {
|
get logger() {
|
||||||
let id = this.id || "<unknown>";
|
let id = this.id || "<unknown>";
|
||||||
return Log.repository.getLogger(LOGGER_ID_BASE + id);
|
return Log.repository.getLogger(LOGGER_ID_BASE + id);
|
||||||
@ -609,6 +611,12 @@ ExtensionData.prototype = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.localeData = new LocaleData({
|
||||||
|
defaultLocale: this.defaultLocale,
|
||||||
|
locales,
|
||||||
|
builtinMessages: this.builtinMessages,
|
||||||
|
});
|
||||||
|
|
||||||
return locales;
|
return locales;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
@ -622,7 +630,6 @@ ExtensionData.prototype = {
|
|||||||
// as returned by |readLocaleFile|.
|
// as returned by |readLocaleFile|.
|
||||||
initAllLocales: Task.async(function* () {
|
initAllLocales: Task.async(function* () {
|
||||||
let locales = yield this.promiseLocales();
|
let locales = yield this.promiseLocales();
|
||||||
this.localeData = new LocaleData({ defaultLocale: this.defaultLocale, locales });
|
|
||||||
|
|
||||||
yield Promise.all(Array.from(locales.keys(),
|
yield Promise.all(Array.from(locales.keys(),
|
||||||
locale => this.readLocaleFile(locale)));
|
locale => this.readLocaleFile(locale)));
|
||||||
@ -651,8 +658,6 @@ ExtensionData.prototype = {
|
|||||||
//
|
//
|
||||||
// If no locales are unavailable, resolves to |null|.
|
// If no locales are unavailable, resolves to |null|.
|
||||||
initLocale: Task.async(function* (locale = this.defaultLocale) {
|
initLocale: Task.async(function* (locale = this.defaultLocale) {
|
||||||
this.localeData = new LocaleData({ defaultLocale: this.defaultLocale });
|
|
||||||
|
|
||||||
if (locale == null) {
|
if (locale == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -970,6 +975,12 @@ Extension.prototype = extend(Object.create(ExtensionData.prototype), {
|
|||||||
this.onShutdown.delete(obj);
|
this.onShutdown.delete(obj);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get builtinMessages() {
|
||||||
|
return new Map([
|
||||||
|
["@@extension_id", this.uuid],
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
|
||||||
// Reads the locale file for the given Gecko-compatible locale code, or if
|
// Reads the locale file for the given Gecko-compatible locale code, or if
|
||||||
// no locale is given, the available locale closest to the UI locale.
|
// no locale is given, the available locale closest to the UI locale.
|
||||||
// Sets the currently selected locale on success.
|
// Sets the currently selected locale on success.
|
||||||
|
@ -113,11 +113,15 @@ function LocaleData(data) {
|
|||||||
this.selectedLocale = data.selectedLocale;
|
this.selectedLocale = data.selectedLocale;
|
||||||
this.locales = data.locales || new Map();
|
this.locales = data.locales || new Map();
|
||||||
|
|
||||||
// Map(locale-name -> Map(message-key -> localized-strings))
|
// Map(locale-name -> Map(message-key -> localized-string))
|
||||||
//
|
//
|
||||||
// Contains a key for each loaded locale, each of which is a
|
// Contains a key for each loaded locale, each of which is a
|
||||||
// Map of message keys to their localized strings.
|
// Map of message keys to their localized strings.
|
||||||
this.messages = data.messages || new Map();
|
this.messages = data.messages || new Map();
|
||||||
|
|
||||||
|
if (data.builtinMessages) {
|
||||||
|
this.messages.set(this.BUILTIN, data.builtinMessages);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LocaleData.prototype = {
|
LocaleData.prototype = {
|
||||||
@ -132,13 +136,15 @@ LocaleData.prototype = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
BUILTIN: "@@BUILTIN_MESSAGES",
|
||||||
|
|
||||||
has(locale) {
|
has(locale) {
|
||||||
return this.messages.has(locale);
|
return this.messages.has(locale);
|
||||||
},
|
},
|
||||||
|
|
||||||
// https://developer.chrome.com/extensions/i18n
|
// https://developer.chrome.com/extensions/i18n
|
||||||
localizeMessage(message, substitutions = [], locale = this.selectedLocale, defaultValue = "??") {
|
localizeMessage(message, substitutions = [], locale = this.selectedLocale, defaultValue = "??") {
|
||||||
let locales = new Set([locale, this.defaultLocale]
|
let locales = new Set([this.BUILTIN, locale, this.defaultLocale]
|
||||||
.filter(locale => this.messages.has(locale)));
|
.filter(locale => this.messages.has(locale)));
|
||||||
|
|
||||||
// Message names are case-insensitive, so normalize them to lower-case.
|
// Message names are case-insensitive, so normalize them to lower-case.
|
||||||
@ -170,15 +176,7 @@ LocaleData.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for certain pre-defined messages.
|
// Check for certain pre-defined messages.
|
||||||
if (message == "@@extension_id") {
|
if (message == "@@ui_locale") {
|
||||||
if ("uuid" in this) {
|
|
||||||
// Per Chrome, this isn't available before an ID is guaranteed
|
|
||||||
// to have been assigned, namely, in manifest files.
|
|
||||||
// This should only be present in instances of the |Extension|
|
|
||||||
// subclass.
|
|
||||||
return this.uuid;
|
|
||||||
}
|
|
||||||
} else if (message == "@@ui_locale") {
|
|
||||||
// Return the browser locale, but convert it to a Chrome-style
|
// Return the browser locale, but convert it to a Chrome-style
|
||||||
// locale code.
|
// locale code.
|
||||||
return Locale.getLocale().replace(/-/g, "_");
|
return Locale.getLocale().replace(/-/g, "_");
|
||||||
|
Loading…
Reference in New Issue
Block a user