[go: nahoru, domu]

Skip to content

Commit

Permalink
Use ES6 classes
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed May 10, 2018
1 parent fd6e25f commit fbcbd8b
Show file tree
Hide file tree
Showing 17 changed files with 952 additions and 949 deletions.
27 changes: 14 additions & 13 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"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"
}
}
33 changes: 16 additions & 17 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,33 +78,32 @@ 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 () {
const self = this;
translateDOM() {
function process(elem, enabled) {
function isAnyOf(searchElement, items) {
return items.indexOf(searchElement) !== -1;
}

function translateAttribute(elem, attr) {
const str = self.get(elem.getAttribute(attr));
const str = this.get(elem.getAttribute(attr));
elem.setAttribute(attr, str);
}

function translateTextNode(node) {
const str = self.get(node.data.trim());
const str = this.get(node.data.trim());
node.data = str;
}

Expand Down Expand Up @@ -160,8 +159,8 @@ Localizer.prototype = {
}

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

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

0 comments on commit fbcbd8b

Please sign in to comment.