mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-10-18 14:13:21 +00:00
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import fs from 'fs';
|
|
import { parse } from 'csv-parse/sync';
|
|
|
|
// Read the csv file with translations
|
|
let csv = fs.readFileSync('translations.csv', 'utf8');
|
|
|
|
// Parse the csv into an array of arrays
|
|
let lines = parse(csv, {
|
|
trim: true,
|
|
quote: '"',
|
|
relax_column_count: true,
|
|
});
|
|
|
|
// Get the list of available languages
|
|
let languages = lines[0];
|
|
languages.shift();
|
|
|
|
// Create an object to store the translations
|
|
let translations = {};
|
|
|
|
// Iterate through the csv lines and add the translations to the `translations` object
|
|
for (let i = 1; i < lines.length; i++) {
|
|
let line = lines[i];
|
|
let key = line[0].replace(/,/g, '');
|
|
line.shift();
|
|
for (let j = 0; j < languages.length; j++) {
|
|
if (!translations[languages[j]]) {
|
|
translations[languages[j]] = {};
|
|
}
|
|
if (line[j]) {
|
|
translations[languages[j]][key] = line[j].trim() || null;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Write the translations back to the language files
|
|
for (let lang in translations) {
|
|
let fileContent = `export default ${JSON.stringify(translations[lang], null, 2)};`;
|
|
fs.writeFileSync(`../src/js/translations/${lang}.mjs`, fileContent);
|
|
}
|
|
|
|
console.log('Translations added successfully.');
|