Add custom locales

This commit is contained in:
CherryKitten 2022-11-29 01:05:16 +01:00
parent 5bb08d8973
commit 84e5189c9a
2 changed files with 13 additions and 2 deletions

1
.gitignore vendored
View File

@ -52,6 +52,7 @@ api-docs.json
ormconfig.json
/custom
packages/backend/assets/instance.css
/locales/custom
# blender backups
*.blend1

View File

@ -4,6 +4,8 @@
const fs = require('fs');
const yaml = require('js-yaml');
let languages = []
let languages_custom = []
const merge = (...args) => args.reduce((a, c) => ({
...a,
@ -13,12 +15,18 @@ const merge = (...args) => args.reduce((a, c) => ({
.reduce((a, [k, v]) => (a[k] = merge(v, c[k]), a), {})
}), {});
languages = []
fs.readdirSync(__dirname).forEach((file) => {
if (file.includes('.yml')){
file = file.slice(0, file.indexOf('.'))
languages.push(file)
languages.push(file);
}
})
fs.readdirSync(__dirname + '/custom').forEach((file) => {
if (file.includes('.yml')){
file = file.slice(0, file.indexOf('.'))
languages_custom.push(file);
}
})
@ -32,6 +40,8 @@ const primaries = {
const clean = (text) => text.replace(new RegExp(String.fromCodePoint(0x08), 'g'), '');
const locales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(`${__dirname}/${c}.yml`, 'utf-8'))) || {}, a), {});
const locales_custom = languages_custom.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(`${__dirname}/custom/${c}.yml`, 'utf-8'))) || {}, a), {});
Object.assign(locales, locales_custom)
module.exports = Object.entries(locales)
.reduce((a, [k ,v]) => (a[k] = (() => {