mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-09 04:10:09 +03:00
feat(i18n): add check mode
This commit is contained in:
parent
5985d53625
commit
2faa87213d
@ -78,6 +78,42 @@ const differenceObject = (
|
|||||||
return { add, remove, modify };
|
return { add, remove, modify };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function warnDiff(diff: { add: string[]; remove: string[]; modify: string[] }) {
|
||||||
|
if (!diff.add.length) {
|
||||||
|
} else {
|
||||||
|
console.log('New keys found:', diff.add.join(', '));
|
||||||
|
//See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-notice-message
|
||||||
|
process.env['CI'] &&
|
||||||
|
console.log(
|
||||||
|
`::notice file=${BASE_JSON_PATH},line=1,title=New keys::${diff.add.join(
|
||||||
|
', '
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (diff.remove.length) {
|
||||||
|
console.warn('[WARN]', 'Unused keys found:', diff.remove.join(', '));
|
||||||
|
process.env['CI'] &&
|
||||||
|
console.warn(
|
||||||
|
`::notice file=${BASE_JSON_PATH},line=1,title=Unused keys::${diff.remove.join(
|
||||||
|
', '
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (diff.modify.length) {
|
||||||
|
console.warn(
|
||||||
|
'[WARN]',
|
||||||
|
'Inconsistent keys found:',
|
||||||
|
diff.modify.join(', ')
|
||||||
|
);
|
||||||
|
process.env['CI'] &&
|
||||||
|
console.warn(
|
||||||
|
`::warning file=${BASE_JSON_PATH},line=1,title=Inconsistent keys::${diff.modify.join(
|
||||||
|
', '
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
console.log('Loading local base translations...');
|
console.log('Loading local base translations...');
|
||||||
const baseLocalTranslations = JSON.parse(
|
const baseLocalTranslations = JSON.parse(
|
||||||
@ -107,17 +143,14 @@ const main = async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
console.log(''); // new line
|
console.log(''); // new line
|
||||||
diff.add.length && console.log('New keys found:', diff.add.join(', '));
|
warnDiff(diff);
|
||||||
diff.remove.length &&
|
|
||||||
console.warn('[WARN]', 'Unused keys found:', diff.remove.join(', '));
|
|
||||||
diff.modify.length &&
|
|
||||||
console.warn(
|
|
||||||
'[WARN]',
|
|
||||||
'Inconsistent keys found:',
|
|
||||||
diff.modify.join(', ')
|
|
||||||
);
|
|
||||||
console.log(''); // new line
|
console.log(''); // new line
|
||||||
|
|
||||||
|
if (process.argv.slice(2).includes('--check')) {
|
||||||
|
// check mode
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
diff.add.forEach(async key => {
|
diff.add.forEach(async key => {
|
||||||
const val = flatLocalTranslations[key];
|
const val = flatLocalTranslations[key];
|
||||||
console.log(`Creating new key: ${key} -> ${val}`);
|
console.log(`Creating new key: ${key} -> ${val}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user