-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check i18n file for missing variables (#18762)
- Loading branch information
1 parent
fb4fd9e
commit 1e608d0
Showing
57 changed files
with
157 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,8 @@ jobs: | |
- run: meteor npm run lint | ||
|
||
- run: meteor npm run translation-check | ||
|
||
- name: Launch MongoDB | ||
uses: wbari/[email protected] | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const fs = require('fs'); | ||
|
||
const fg = require('fast-glob'); | ||
|
||
const checkFiles = async (path, source) => { | ||
const sourceFile = JSON.parse(fs.readFileSync(`${ path }${ source }`, 'utf8')); | ||
|
||
const regexVar = /__([a-zA-Z_]+?)__/g; | ||
|
||
const usedKeys = Object.entries(sourceFile) | ||
.filter(([, value]) => regexVar.exec(value)) | ||
.map(([key, value]) => { | ||
const replaces = value.match(regexVar); | ||
return { | ||
key, | ||
replaces, | ||
}; | ||
}); | ||
|
||
const validateKeys = (json) => | ||
usedKeys | ||
.filter(({ key }) => typeof json[key] !== 'undefined') | ||
.reduce((prev, cur) => { | ||
const { key, replaces } = cur; | ||
|
||
const miss = replaces.filter((replace) => json[key].indexOf(replace) === -1); | ||
|
||
if (miss.length > 0) { | ||
prev.push({ key, miss }); | ||
} | ||
|
||
return prev; | ||
}, []); | ||
|
||
const i18nFiles = await fg([`${ path }/**/*.i18n.json`]); | ||
|
||
// const getInvalidKeys = (json) => | ||
// usedKeys | ||
// .filter(({ key }) => typeof json[key] !== 'undefined') | ||
// .filter(({ key, replaces }) => { | ||
// const miss = replaces.filter((replace) => json[key].indexOf(replace) === -1); | ||
|
||
// return miss.length > 0; | ||
// }) | ||
// .map(({ key }) => key); | ||
|
||
// const removeMissingKeys = () => { | ||
// const allKeys = Object.keys(sourceFile); | ||
// i18nFiles.forEach((file) => { | ||
// const json = JSON.parse(fs.readFileSync(file, 'utf8')); | ||
|
||
// const invalidKeys = getInvalidKeys(json); | ||
|
||
// const validKeys = allKeys.filter((key) => !invalidKeys.includes(key)); | ||
// // console.log('validKeys', file, validKeys); | ||
|
||
// fs.writeFileSync(file, JSON.stringify(json, validKeys, 2)); | ||
// }); | ||
// }; | ||
|
||
let totalErrors = 0; | ||
i18nFiles.filter((file) => { | ||
const json = JSON.parse(fs.readFileSync(file, 'utf8')); | ||
|
||
const result = validateKeys(json); | ||
|
||
if (result.length === 0) { | ||
return true; | ||
} | ||
|
||
totalErrors += result.length; | ||
|
||
console.log('\n## File', file, `(${ result.length } errors)`); | ||
|
||
result.forEach(({ key, miss }) => { | ||
console.log('\n- Key:', key, '\n Missing variables:', miss.join(', ')); | ||
}); | ||
|
||
return false; | ||
}); | ||
|
||
if (totalErrors > 0) { | ||
console.error(`\n${ totalErrors } errors found`); | ||
process.exit(1); | ||
} | ||
|
||
process.exit(0); | ||
}; | ||
|
||
checkFiles('./packages/rocketchat-i18n', '/i18n/en.i18n.json'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{ } | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.