* cleaner locales

* WIP locales sanity
This commit is contained in:
Mylloon 2022-07-22 00:05:49 +02:00
parent f446913cd5
commit fc3a2640ca
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,17 +1,17 @@
import { Client } from 'discord.js';
import { readdir } from 'fs/promises';
import { removeExtension } from './misc';
/**
* Load the localizations files
*/
export const loadLocales = async () => {
// Check if there is a defined valid value
const old_path = __dirname.split('/');
old_path.pop();
const files = await readdir(`${old_path.join('/')}/locales`);
const locales = new Map();
const locales = new Map<string, Map<string, string>>();
await Promise.all(
files.map(async lang => {
const content: {
@ -21,9 +21,11 @@ export const loadLocales = async () => {
);
locales.set(
lang.split('.')[0],
removeExtension(lang),
new Map(
Object.keys(content).map(str => {
Object.keys(content)
.filter(str => str !== 'default')
.map(str => {
return [str, content[str]];
}),
)
@ -31,6 +33,9 @@ export const loadLocales = async () => {
})
);
// Check locales sanity
checkLocales(locales);
return locales;
};
@ -69,10 +74,21 @@ export const getLocale = (client: Client, lang: string) => {
const locales = new Map();
default_locales?.forEach((_, key) => {
if (key !== 'default') {
locales.set(key, desired_locales?.get(key) ?? default_locales.get(key));
}
});
return locales;
};
/**
* Check if locales are sane
* WARN if translation aren't 100%
* ERROR if default lang isn't 100%
* @param locales Locales loaded
* @returns void
*/
export const checkLocales = async (locales: Map<string, Map<string, string>>) => {
console.log(locales);
return;
};