Compare commits
No commits in common. "b6247551dca019be863ef23799bb67dad6727834" and "fc3a2640caae117c7437902e8c554dd914af6bf5" have entirely different histories.
b6247551dc
...
fc3a2640ca
3 changed files with 11 additions and 65 deletions
|
@ -20,7 +20,7 @@
|
||||||
"curly": ["error", "multi-line", "consistent"],
|
"curly": ["error", "multi-line", "consistent"],
|
||||||
"dot-location": ["error", "property"],
|
"dot-location": ["error", "property"],
|
||||||
"handle-callback-err": "off",
|
"handle-callback-err": "off",
|
||||||
"indent": ["error", "tab", { "SwitchCase": 1 }],
|
"indent": ["error", "tab"],
|
||||||
"keyword-spacing": "error",
|
"keyword-spacing": "error",
|
||||||
"max-nested-callbacks": ["error", { "max": 4 }],
|
"max-nested-callbacks": ["error", { "max": 4 }],
|
||||||
"max-statements-per-line": ["error", { "max": 2 }],
|
"max-statements-per-line": ["error", { "max": 2 }],
|
||||||
|
|
|
@ -43,8 +43,7 @@ export default async () => {
|
||||||
|
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
console.log('Localizations progression :');
|
client.locales = await loadLocales();
|
||||||
client.locales = await loadLocales(client.config.default_lang);
|
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,11 +3,9 @@ import { readdir } from 'fs/promises';
|
||||||
import { removeExtension } from './misc';
|
import { removeExtension } from './misc';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the localizations files into memory
|
* Load the localizations files
|
||||||
* @param default_lang default lang
|
|
||||||
* @returns Map of map with all the localizations
|
|
||||||
*/
|
*/
|
||||||
export const loadLocales = async (default_lang: string) => {
|
export const loadLocales = async () => {
|
||||||
const old_path = __dirname.split('/');
|
const old_path = __dirname.split('/');
|
||||||
old_path.pop();
|
old_path.pop();
|
||||||
|
|
||||||
|
@ -36,7 +34,7 @@ export const loadLocales = async (default_lang: string) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check locales sanity
|
// Check locales sanity
|
||||||
checkLocales(locales, default_lang);
|
checkLocales(locales);
|
||||||
|
|
||||||
return locales;
|
return locales;
|
||||||
};
|
};
|
||||||
|
@ -83,65 +81,14 @@ export const getLocale = (client: Client, lang: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show percentage of translation progression
|
* Check if locales are sane
|
||||||
*
|
* WARN if translation aren't 100%
|
||||||
* Raise an error if the default lang isn't
|
* ERROR if default lang isn't 100%
|
||||||
* the lang with most text
|
|
||||||
* @param locales Locales loaded
|
* @param locales Locales loaded
|
||||||
* @param default_lang default lang
|
|
||||||
* @returns void
|
* @returns void
|
||||||
*/
|
*/
|
||||||
export const checkLocales =
|
export const checkLocales = async (locales: Map<string, Map<string, string>>) => {
|
||||||
async (locales: Map<string, Map<string, string>>, default_lang: string) => {
|
console.log(locales);
|
||||||
// Associate each lang with the number of locale it has
|
|
||||||
let locales_size = new Map<string, number>();
|
|
||||||
locales.forEach((locales_data, lang) => {
|
|
||||||
locales_size.set(lang, locales_data.size);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sort the map
|
return;
|
||||||
locales_size = new Map([...locales_size.entries()]
|
|
||||||
.sort((a, b) => b[1] - a[1]));
|
|
||||||
|
|
||||||
// Check if default lang is 100%
|
|
||||||
const [max_size_name] = locales_size.keys();
|
|
||||||
const [max_size] = locales_size.values();
|
|
||||||
const default_lang_size = locales_size.get(default_lang) ?? 0;
|
|
||||||
if (max_size > default_lang_size) {
|
|
||||||
throw new Error(
|
|
||||||
`The default locale (${default_lang} = ${default_lang_size}) isn't complete `
|
|
||||||
+ `(${max_size_name} = ${max_size}).`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the default language as it is used as a reference
|
|
||||||
locales_size.delete(default_lang);
|
|
||||||
|
|
||||||
// Displays the percentages according to the default language
|
|
||||||
// lower is bigger
|
|
||||||
const bar_size = 4;
|
|
||||||
locales_size.forEach((size, lang) => {
|
|
||||||
const percentage = (size / max_size) * 100;
|
|
||||||
const blocks = ' '.repeat(percentage / bar_size);
|
|
||||||
const blank = ' '.repeat((100 - percentage) / bar_size);
|
|
||||||
const color = () => {
|
|
||||||
switch (true) {
|
|
||||||
case percentage <= 25:
|
|
||||||
// red
|
|
||||||
return '\x1b[41m';
|
|
||||||
case percentage <= 50:
|
|
||||||
// mangeta
|
|
||||||
return '\x1b[45m';
|
|
||||||
case percentage <= 75:
|
|
||||||
// cyan
|
|
||||||
return '\x1b[46m';
|
|
||||||
case percentage <= 100:
|
|
||||||
// green
|
|
||||||
return '\x1b[42m';
|
|
||||||
default:
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
console.log(`${lang} | ${color()}${blocks}\x1b[0m${blank} | ${percentage}%`);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue