Add a tool to detect possible unused language keys and untranslated keys#34737
Add a tool to detect possible unused language keys and untranslated keys#34737lunny wants to merge 17 commits intogo-gitea:mainfrom
Conversation
183f1cd to
760bf0d
Compare
|
I think you can add this command to the Makefile. |
|
Can you move the tool to Also maybe add a convenience |
|
I disagree, sometimes you have simple words to translate, and top-level is ideal for them. Unsearchability is a tooling issue. |
Yes, I suppose this is because it serially walks the files while such a operation could and should be parallelized (maybe with limited concurrency to stay within OS open file number limits). |
It's impossible to build a correct tool to resolve the "tooling issue". If you think yes, please show a feasible solution. |
I think it's purely a algorithm problem, no parallelization is needed ...... |
Yeah, I was just refering to |
Could introduce a prefix to all translations like |
|
I skimmed through this and if I'm understanding correctly it's looking through all files for each key. something similar in shell (fish but I don't think any specific syntax from it is used). bare in mind it probably is missing keys as it's a quick PoC. rg "TrN? \"([\w._]*)\"" -o --no-filename --no-line-number -r '$1' >keys #find all Tr(N)s from templates
rg "Tr?N\(\"(.*)\"\)" -o --no-filename --no-line-number -r '$1' >> keys # find all Tr(N)s from go files
sort keys | uniq > keys_in_code # sort for comparison
rg "(.*) = .*" options/locale/locale_en-US.ini -N -r '$1' | sort |uniq > keys_in_locale # strip to keys and sort
comm keys_in_locale keys_in_code -32 # list every key in locale which wasn't in codeDisregard - this does not take locale being in ini format so it's wrong. |
The challenge is like this: |
|
Ah. True, that complicates things. |
Another locale tool, backport-locale, is located under the build directory. Therefore, I think it makes sense to keep them together. How about moving the entire build directory under tools, as tools/build? |
|
OK. I pushed a commit. Now it will take about 15s so that I also introduced it in CI for pull request. |
improve, now it's about 15s.
Yes. This tool just check unused keys but not check missed keys.
|
|
Still would like the script moved to |
|
Still I think it needs to address 2 & 3 |
When do some translations, I found some keys have never been used. So that I wrote a tool to help to avoid unused language keys.
the tool will search all
.go(except test go files) or.tmplfiles to find"$key"to detect whether the language keys are being used. This cannot cover all the situations, i.e. some keys are composited dynamically. So that manually check is necessary. There is a whitelist with glob syntax to manually skip such a situation.tools/i18n/.