Created
March 3, 2020 19:39
-
-
Save hto/da14993198e348ec7ba61f414d18b133 to your computer and use it in GitHub Desktop.
Javascript simple localization methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| currentLang: 'en', | |
| textList: null, | |
| setLang: function(lang) { | |
| this.currentLang = lang; | |
| this.textList = require(lang); | |
| }, | |
| __t: function(key) { | |
| return typeof this.textList[key] === "undefined" ? "-" : this.textList[key]; | |
| }, | |
| __s: function(...key) { | |
| return typeof this.textList[key[0]] === "undefined" ? "-" : (this.textList[key[0]]).replace('%s1',key[1]).replace('%s2', key[2]); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
language files that should be in the same directory