mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Added language names for all supported locales.
This commit is contained in:
parent
de55496ac9
commit
6923ea4d1d
77 changed files with 154 additions and 1 deletions
39
scripts/download-language-names.js
Normal file
39
scripts/download-language-names.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const https = require('https');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const src = path.resolve(__dirname, '../lang');
|
||||
const dest = path.resolve(__dirname, '../public/language');
|
||||
const files = fs.readdirSync(src);
|
||||
|
||||
const getUrl = locale =>
|
||||
`https://raw.githubusercontent.com/umpirsky/language-list/master/data/${locale}/language.json`;
|
||||
|
||||
const asyncForEach = async (array, callback) => {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
await callback(array[index], index, array);
|
||||
}
|
||||
};
|
||||
|
||||
if (!fs.existsSync(dest)) {
|
||||
fs.mkdirSync(dest);
|
||||
}
|
||||
|
||||
const download = async files => {
|
||||
await asyncForEach(files, async file => {
|
||||
const locale = file.replace('-', '_').replace('.json', '');
|
||||
|
||||
const filename = path.join(dest, file);
|
||||
if (!fs.existsSync(filename)) {
|
||||
await new Promise(resolve => {
|
||||
https.get(getUrl(locale), res => {
|
||||
console.log('Downloaded', chalk.greenBright('->'), filename);
|
||||
resolve(res.pipe(fs.createWriteStream(filename)));
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
download(files);
|
||||
Loading…
Add table
Add a link
Reference in a new issue