mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
chore: add custom watch task for translation extraction
This commit is contained in:
parent
69161472eb
commit
54960f3c7a
4 changed files with 41 additions and 29 deletions
3
tools/extract-i18n-single.js
Normal file
3
tools/extract-i18n-single.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
const extractI18n = require('./extract-i18n');
|
||||
|
||||
extractI18n();
|
||||
7
tools/extract-i18n-watch.js
Normal file
7
tools/extract-i18n-watch.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
const extractI18n = require('./extract-i18n');
|
||||
const fs = require('fs');
|
||||
const MAIN_TRANSLATION_FILE = __dirname + '/../src/assets/i18n/en.json';
|
||||
|
||||
fs.watchFile(MAIN_TRANSLATION_FILE, () => {
|
||||
extractI18n();
|
||||
});
|
||||
|
|
@ -1,37 +1,38 @@
|
|||
const fs = require('fs');
|
||||
const path = __dirname + '/../src/assets/i18n/en.json';
|
||||
console.log(path);
|
||||
|
||||
const _tr = fs.readFileSync(path);
|
||||
const tr = JSON.parse(_tr);
|
||||
module.exports = () => {
|
||||
const _tr = fs.readFileSync(path);
|
||||
const tr = JSON.parse(_tr);
|
||||
|
||||
const parse = (o, pref = '') => {
|
||||
return Object.keys(o).reduce((acc, key) => {
|
||||
console.log(key);
|
||||
const parse = (o, pref = '') => {
|
||||
return Object.keys(o).reduce((acc, key) => {
|
||||
console.log(key);
|
||||
|
||||
if (typeof o[key] === 'object') {
|
||||
return {
|
||||
...acc,
|
||||
[key]: parse(o[key], key + '.'),
|
||||
};
|
||||
} else if (typeof o[key] === 'string') {
|
||||
return {
|
||||
...acc,
|
||||
[key]: pref + key,
|
||||
};
|
||||
} else {
|
||||
throw 'Invalid Data';
|
||||
}
|
||||
}, {});
|
||||
};
|
||||
if (typeof o[key] === 'object') {
|
||||
return {
|
||||
...acc,
|
||||
[key]: parse(o[key], pref + key + '.'),
|
||||
};
|
||||
} else if (typeof o[key] === 'string') {
|
||||
return {
|
||||
...acc,
|
||||
[key]: pref + key,
|
||||
};
|
||||
} else {
|
||||
throw 'Invalid Data';
|
||||
}
|
||||
}, {});
|
||||
};
|
||||
|
||||
const parsed = parse(tr);
|
||||
console.log(parsed);
|
||||
const string = `export const T = ${JSON.stringify(parsed, null, 2)};
|
||||
const parsed = parse(tr);
|
||||
console.log(parsed);
|
||||
const string = `export const T = ${JSON.stringify(parsed, null, 2)};
|
||||
`.replace(/"/g, '\'');
|
||||
|
||||
|
||||
fs.writeFileSync(__dirname + '/../src/app/t.const.ts', string, {
|
||||
overwrite: true,
|
||||
flag: 'w'
|
||||
});
|
||||
fs.writeFileSync(__dirname + '/../src/app/t.const.ts', string, {
|
||||
overwrite: true,
|
||||
flag: 'w'
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue