mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Add i18n-sync script
This commit is contained in:
parent
b3b7ee4f6e
commit
2009d13995
@ -28,11 +28,18 @@ const extractKeys = (language) => {
|
||||
return new LanguageKeys(mapKeys, regexKeys);
|
||||
};
|
||||
const mainLanguageKey = extractKeys(readFile(path_1.join(config.folder, `i18n.${config.mainLanguage}.js`)));
|
||||
const targetLanguages = config.targetLanguages.map(l => readFile(path_1.join(config.folder, `i18n.${l}.js`)));
|
||||
const targetLanguages = config.targetLanguages.map(name => {
|
||||
const path = path_1.join(config.folder, `i18n.${name}.js`);
|
||||
return {
|
||||
name,
|
||||
path,
|
||||
text: readFile(path)
|
||||
};
|
||||
});
|
||||
targetLanguages.forEach(language => {
|
||||
const diff = mainLanguageKey.diff(extractKeys(language));
|
||||
const output = language
|
||||
const diff = mainLanguageKey.diff(extractKeys(language.text));
|
||||
const output = language.text
|
||||
.replace(/([\s\n]*\[`\*`)/, `\n ${diff.mapKeys.map(k => '[`' + k + '`, `TODO:`],').join('\n ')}$1`)
|
||||
.replace(/(\]\);?[\s\n]*export default)/, ` ${diff.regexKeys.map(k => '[' + k + ', `TODO:`],').join('\n ')}\n$1`);
|
||||
console.log(output);
|
||||
fs_1.writeFileSync(language.path, output, { encoding: 'utf-8' });
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
interface Config {
|
||||
@ -38,11 +38,18 @@ const extractKeys = (language: string) => {
|
||||
}
|
||||
|
||||
const mainLanguageKey = extractKeys(readFile(join(config.folder, `i18n.${config.mainLanguage}.js`)))
|
||||
const targetLanguages = config.targetLanguages.map(l => readFile(join(config.folder, `i18n.${l}.js`)))
|
||||
const targetLanguages = config.targetLanguages.map(name => {
|
||||
const path = join(config.folder, `i18n.${name}.js`)
|
||||
return {
|
||||
name,
|
||||
path,
|
||||
text: readFile(path)
|
||||
}
|
||||
})
|
||||
targetLanguages.forEach(language => {
|
||||
const diff = mainLanguageKey.diff(extractKeys(language))
|
||||
const output = language
|
||||
const diff = mainLanguageKey.diff(extractKeys(language.text))
|
||||
const output = language.text
|
||||
.replace(/([\s\n]*\[`\*`)/, `\n ${diff.mapKeys.map(k => '[`' + k + '`, `TODO:`],').join('\n ')}$1`)
|
||||
.replace(/(\]\);?[\s\n]*export default)/, ` ${diff.regexKeys.map(k => '[' + k + ', `TODO:`],').join('\n ')}\n$1`)
|
||||
console.log(output)
|
||||
writeFileSync(language.path, output, { encoding: 'utf-8' })
|
||||
})
|
||||
Loading…
Reference in New Issue
Block a user