Refactor the IL10n
implementations to utilize async
methods rather than manually returning Promise
s
This changes the methods signatures of `GenericL10n`, `MozL10n`, and `NullL10n`.
This commit is contained in:
parent
af89ec271d
commit
b0fa02e845
@ -145,21 +145,20 @@ class MozL10n {
|
||||
this.mozL10n = mozL10n;
|
||||
}
|
||||
|
||||
getLanguage() {
|
||||
return Promise.resolve(this.mozL10n.getLanguage());
|
||||
async getLanguage() {
|
||||
return this.mozL10n.getLanguage();
|
||||
}
|
||||
|
||||
getDirection() {
|
||||
return Promise.resolve(this.mozL10n.getDirection());
|
||||
async getDirection() {
|
||||
return this.mozL10n.getDirection();
|
||||
}
|
||||
|
||||
get(property, args, fallback) {
|
||||
return Promise.resolve(this.mozL10n.get(property, args, fallback));
|
||||
async get(property, args, fallback) {
|
||||
return this.mozL10n.get(property, args, fallback);
|
||||
}
|
||||
|
||||
translate(element) {
|
||||
async translate(element) {
|
||||
this.mozL10n.translate(element);
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,28 +27,24 @@ class GenericL10n {
|
||||
});
|
||||
}
|
||||
|
||||
getLanguage() {
|
||||
return this._ready.then((l10n) => {
|
||||
return l10n.getLanguage();
|
||||
});
|
||||
async getLanguage() {
|
||||
const l10n = await this._ready;
|
||||
return l10n.getLanguage();
|
||||
}
|
||||
|
||||
getDirection() {
|
||||
return this._ready.then((l10n) => {
|
||||
return l10n.getDirection();
|
||||
});
|
||||
async getDirection() {
|
||||
const l10n = await this._ready;
|
||||
return l10n.getDirection();
|
||||
}
|
||||
|
||||
get(property, args, fallback) {
|
||||
return this._ready.then((l10n) => {
|
||||
return l10n.get(property, args, fallback);
|
||||
});
|
||||
async get(property, args, fallback) {
|
||||
const l10n = await this._ready;
|
||||
return l10n.get(property, args, fallback);
|
||||
}
|
||||
|
||||
translate(element) {
|
||||
return this._ready.then((l10n) => {
|
||||
return l10n.translate(element);
|
||||
});
|
||||
async translate(element) {
|
||||
const l10n = await this._ready;
|
||||
return l10n.translate(element);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,12 +163,12 @@ class IL10n {
|
||||
/**
|
||||
* @returns {Promise<string>} - Resolves to the current locale.
|
||||
*/
|
||||
getLanguage() {}
|
||||
async getLanguage() {}
|
||||
|
||||
/**
|
||||
* @returns {Promise<string>} - Resolves to 'rtl' or 'ltr'.
|
||||
*/
|
||||
getDirection() {}
|
||||
async getDirection() {}
|
||||
|
||||
/**
|
||||
* Translates text identified by the key and adds/formats data using the args
|
||||
@ -179,12 +179,12 @@ class IL10n {
|
||||
* @param {string} fallback
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
get(key, args, fallback) { }
|
||||
async get(key, args, fallback) { }
|
||||
|
||||
/**
|
||||
* Translates HTML element.
|
||||
* @param {HTMLElement} element
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
translate(element) { }
|
||||
async translate(element) { }
|
||||
}
|
||||
|
@ -56,21 +56,19 @@ function formatL10nValue(text, args) {
|
||||
* @implements {IL10n}
|
||||
*/
|
||||
let NullL10n = {
|
||||
getLanguage() {
|
||||
return Promise.resolve('en-us');
|
||||
async getLanguage() {
|
||||
return 'en-us';
|
||||
},
|
||||
|
||||
getDirection() {
|
||||
return Promise.resolve('ltr');
|
||||
async getDirection() {
|
||||
return 'ltr';
|
||||
},
|
||||
|
||||
get(property, args, fallback) {
|
||||
return Promise.resolve(formatL10nValue(fallback, args));
|
||||
async get(property, args, fallback) {
|
||||
return formatL10nValue(fallback, args);
|
||||
},
|
||||
|
||||
translate(element) {
|
||||
return Promise.resolve();
|
||||
},
|
||||
async translate(element) { },
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user