Use ES6 classes

Always use the shorthand notation if the function is a method of an object or class `{ foo() { ... } }` or `class bar { foo() { ... } }`
unless it's a callback in which case you a fat arrow function should be used `{ cb: () => { ... } }`
This commit is contained in:
Juanjo Diaz
2018-07-05 21:31:56 +02:00
parent 67fefcf184
commit 0e4808bf6f
20 changed files with 977 additions and 972 deletions
+15 -14
View File
@@ -10,17 +10,17 @@
* Localization Utilities
*/
export function Localizer() {
// Currently configured language
this.language = 'en';
export class Localizer {
constructor() {
// Currently configured language
this.language = 'en';
// Current dictionary of translations
this.dictionary = undefined;
}
// Current dictionary of translations
this.dictionary = undefined;
}
Localizer.prototype = {
// Configure suitable language based on user preferences
setup: function (supportedLanguages) {
setup(supportedLanguages) {
this.language = 'en'; // Default: US English
/*
@@ -78,21 +78,22 @@ Localizer.prototype = {
return;
}
}
},
}
// Retrieve localised text
get: function (id) {
get(id) {
if (typeof this.dictionary !== 'undefined' && this.dictionary[id]) {
return this.dictionary[id];
} else {
return id;
}
},
}
// Traverses the DOM and translates relevant fields
// See https://html.spec.whatwg.org/multipage/dom.html#attr-translate
translateDOM: function () {
translateDOM() {
const self = this;
function process(elem, enabled) {
function isAnyOf(searchElement, items) {
return items.indexOf(searchElement) !== -1;
@@ -160,8 +161,8 @@ Localizer.prototype = {
}
process(document.body, true);
},
};
}
}
export const l10n = new Localizer();
export default l10n.get.bind(l10n);