-
Notifications
You must be signed in to change notification settings - Fork 100
/
index.js
27 lines (24 loc) · 792 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const fs = require('node:fs')
const path = require('node:path')
const { default: mi18n } = require('mi18n')
/**
* Represents a collection of language files.
* @typedef {Object} LangFiles
* @property {Object} [locale] - The language locale.
* @property {string} [locale.langKey] - The language key.
*/
/**
* Reads and processes language files from the specified directory.
* @type {LangFiles}
*/
const langFiles = fs.readdirSync(__dirname).reduce((acc, lang) => {
if (!/.lang$/.test(lang)) {
return acc
}
const langFile = fs.readFileSync(path.resolve(__dirname, lang)).toString()
const fileName = path.basename(lang)
const locale = fileName.substring(0, fileName.indexOf('.'))
acc[locale] = mi18n.processFile(langFile)
return acc
}, {})
module.exports = langFiles