Script to generate reports on translation use
RFC The script is used to create three files.
report.json is a json file which contains all translation keys found, state their occurrences across the code, has their translation when there is one available and state if the key is a variable called in the code (in which case, it would be difficult to find all keys that could match this one)
report.txt is a human readable version of the same report
non_explicitly_used_keys.txt is a report which lists all translations for which there was no explicit translation found (i.e : all translations currently specified, but not in the previous reports). We cannot guarantee that they are not used.
We could still upgrade the script by checking for ternary operators which gives explicit values, but this will suffice for a first draft
usage : npm run check:translations
If this is sufficient, it's usable (even if we can't find every usage) I'm still going to check for ternary operators (we have 2 keys which use those), or cases where there is a null / false check before assigning a value to translate, they are currently counted as "non explicit".
@hansmannj : once you've run it, feel free to tell me what you'd like to change to make files that are easier to read.
Passing run #2328 ↗︎
Details:
| taking into account difference between variables and static keys | |||
| Project: web-mapviewer | Commit: b901d87037 |
||
| Status: Passed | Duration: 05:44 💡 | ||
| Started: May 28, 2024 7:35 AM | Ended: May 28, 2024 7:40 AM | ||
Review all test suite changes for PR #861 ↗︎
Thanks @ltkum , I also added @pakb and @ltshb as reviewers here, since I don't want to be the bottleneck here. It looks good to me, but I did not yet have time to test it. Would be good though to have the extracted files soon, so I can send them to our colleagues who support us with checking the translations. I'll try to reserve some time for that on Wednesday at the latest (in case I don't find a slot today..).
Thanks a lot for creating the extraction scripts!
@ltkum I got this error when trying to run the script
npm run check:translations
> check:translations
> node scripts/check-translations.js
node:fs:744
handleErrorFromBinding(ctx);
^
Error: EISDIR: illegal operation on a directory, read
at Object.readSync (node:fs:744:3)
at tryReadSync (node:fs:444:20)
at Object.readFileSync (node:fs:490:19)
at file:///home/ltshb/repositories/web-mapviewer/scripts/check-translations.js:81:36
at Array.forEach (<anonymous>)
at searchDirectory (file:///home/ltshb/repositories/web-mapviewer/scripts/check-translations.js:74:11)
at file:///home/ltshb/repositories/web-mapviewer/scripts/check-translations.js:146:13
at Array.forEach (<anonymous>)
at searchDirectory (file:///home/ltshb/repositories/web-mapviewer/scripts/check-translations.js:74:11)
at file:///home/ltshb/repositories/web-mapviewer/scripts/check-translations.js:146:13 {
errno: -21,
syscall: 'read',
code: 'EISDIR'
}
Node.js v18.20.3
This is not a priority : we'll revisit this after deploy.