#598: Add localization support to the panel + scripts

This commit is contained in:
Elio Struyf committed 2023-07-04 10:53:35 +02:00
1 parent 71743bf292
commit c247af449a
25 files changed
+207 -40

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
const fs = require('fs');
const path = require('path');
const camlCase = (str) => {
const words = str.split('.');
const firstWord = words.shift();
const rest = words.map((word) => {
return word.charAt(0).toUpperCase() + word.slice(1);
});
return firstWord + rest.join('');
};
(async () => {
// Get the EN file
const enFile = fs.readFileSync(path.join(__dirname, '../l10n/bundle.l10n.json'), 'utf8');
// Parse the EN file
const en = JSON.parse(enFile);
const keys = Object.keys(en);
// Create an enum file
const enumFile = fs.createWriteStream(path.join(__dirname, '../src/localization/localization.enum.ts'));
// Write the enum file header
enumFile.write(`export enum LocalizationKey {\n`);
// Write the enum values
keys.forEach((key, index) => {
enumFile.write(` ${camlCase(key)} = '${key}'${index === keys.length - 1 ? '' : ','}\n`);
});
// Write the enum file footer
enumFile.write(`}\n`);
// Close the enum file
enumFile.close();
})();
+33
View File
@@ -0,0 +1,33 @@
const fs = require('fs');
const path = require('path');
(async () => {
// Get all the files from the l10n directory
const files = fs.readdirSync(path.join(__dirname, '../l10n'));
// Get the EN file
const enFile = fs.readFileSync(path.join(__dirname, '../l10n/bundle.l10n.json'), 'utf8');
const enContent = JSON.parse(enFile);
const enKeys = Object.keys(enContent);
for (const file of files) {
if (file.endsWith(`bundle.l10n.json`)) {
continue;
}
// Get the file content
const fileContent = fs.readFileSync(path.join(__dirname, `../l10n/${file}`), 'utf8');
const content = JSON.parse(fileContent);
// Loop through the EN keys
for (const key of enKeys) {
// If the key does not exist in the file, add it
if (!content[key]) {
content[key] = `🚧: ${enContent[key]}`;
}
}
// Write the file
fs.writeFileSync(path.join(__dirname, `../l10n/${file}`), JSON.stringify(content, null, 2), 'utf8');
}
})();