mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-10 02:42:55 +02:00
#598: Add localization support to the panel + scripts
This commit is contained in:
@@ -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();
|
||||
})();
|
||||
Reference in New Issue
Block a user