()
| 20 | } |
| 21 | |
| 22 | async load() { |
| 23 | const localeDir = `${this.base}/${this.lang}`; |
| 24 | let files = await fs.readdir(localeDir); |
| 25 | files = [this.defaultLocale].concat(files.filter(file => file !== this.defaultLocale)); |
| 26 | for (const file of files) { |
| 27 | const ext = path.extname(file); |
| 28 | const transformer = transformers[ext]; |
| 29 | if (transformer) { |
| 30 | try { |
| 31 | const res = await fs.readFile(`${localeDir}/${file}`, 'utf8'); |
| 32 | Object.assign(this.data, transformer(res)); |
| 33 | } catch (err) { |
| 34 | if (err.code !== 'ENOENT') { |
| 35 | throw err; |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | Object.keys(this.data) |
| 41 | .forEach(key => { |
| 42 | this.desc[key] = this.desc[key] || this.data[key].description; |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | getMessage(key, def) { |
| 47 | const item = this.data[key]; |
no test coverage detected