[go: nahoru, domu]

Skip to content

Commit

Permalink
Use ES6 classes
Browse files Browse the repository at this point in the history
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: () => { ... } }`
  • Loading branch information
juanjoDiaz committed Jul 12, 2018
1 parent 67fefcf commit 0e4808b
Show file tree
Hide file tree
Showing 20 changed files with 997 additions and 992 deletions.
28 changes: 15 additions & 13 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"env": {
"browser": true,
"es6": true
},
"parserOptions": {
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
"no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": true }],
"no-constant-condition": ["error", { "checkLoops": false }],
"no-var": "error"
}
"env": {
"browser": true,
"es6": true
},
"parserOptions": {
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
"no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": true }],
"no-constant-condition": ["error", { "checkLoops": false }],
"no-var": "error",
"no-useless-constructor": "error",
"object-shorthand": ["error", "methods", { "avoidQuotes": true }],
}
}
29 changes: 15 additions & 14 deletions app/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -160,8 +161,8 @@ Localizer.prototype = {
}

process(document.body, true);
},
};
}
}

export const l10n = new Localizer();
export default l10n.get.bind(l10n);
Loading

0 comments on commit 0e4808b

Please sign in to comment.