-
-
Notifications
You must be signed in to change notification settings - Fork 118
[feature] Automate generation of test-translation.json from .po files #1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[feature] Automate generation of test-translation.json from .po files #1018
Conversation
- Add script to parse .po files - Update test-translation.json with complete translations - Fix test expecting raw key instead of translation Closes openwisp#902
📝 WalkthroughWalkthroughA Node.js script (scripts/generate-test-translations.js) was added to parse i18n/en.po and generate client/test-translation.json by extracting msgid→msgstr pairs. client/test-translation.json was substantially reworked: many translation keys were added, renamed, or removed and msgstr values populated. The Status component test (client/components/status/status.test.js) was updated to assert the full translated error message "The WiFi session ended. You can log in again to start a new session." instead of a translation key. A minor grammar fix was made in i18n/en.po. Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev_CI as "Dev / CI"
participant Script as "scripts/generate-test-translations.js"
participant PO as "i18n/en.po"
participant JSON as "client/test-translation.json"
participant Tests as "Test Runner / Status Test"
Dev_CI->>Script: invoke script
Script->>PO: read en.po
Script->>Script: parse msgid/msgstr entries
Script->>JSON: write translations object
Script->>Dev_CI: log generated path & count
Dev_CI->>Tests: run tests
Tests->>JSON: load translations
Tests->>Tests: assert full msgstr used in status error toast
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (3)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@client/test-translation.json`:
- Around line 386-390: The string PWD_RESET_ADD_TXT contains an ungrammatical
phrase; update the source entry in i18n/en.po for msgid "PWD_RESET_ADD_TXT" to
use "Have you forgotten your password? Enter your email address, phone number or
username below and we'll send you the instructions to reset it." (or preferred
wording), then regenerate the generated JSON/translations so
client/test-translation.json reflects the corrected text; verify the key
PWD_RESET_ADD_TXT and resulting msgstr are updated.
🧹 Nitpick comments (1)
scripts/generate-test-translations.js (1)
4-5: Make I/O paths robust to non-root CWD.Relative paths assume the script runs from the repo root. Using
path.resolve(__dirname, ...)prevents failures when invoked from other working directories.♻️ Suggested change
-const fs = require("fs"); +const fs = require("fs"); +const path = require("path"); @@ -const poFile = fs.readFileSync("./i18n/en.po", "utf8"); +const poPath = path.resolve(__dirname, "../i18n/en.po"); +const poFile = fs.readFileSync(poPath, "utf8"); @@ -const outputPath = "./client/test-translation.json"; +const outputPath = path.resolve(__dirname, "../client/test-translation.json");Also applies to: 68-70
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
client/components/password-reset/__snapshots__/password-reset.test.js.snapis excluded by!**/*.snapclient/components/registration/__snapshots__/registration.test.js.snapis excluded by!**/*.snapclient/components/status/__snapshots__/status.test.js.snapis excluded by!**/*.snap
📒 Files selected for processing (3)
client/components/status/status.test.jsclient/test-translation.jsonscripts/generate-test-translations.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Tests and Coverage
- GitHub Check: QA-Checks
🔇 Additional comments (2)
client/components/status/status.test.js (1)
1501-1510: LGTM: assertion now validates resolved message text.scripts/generate-test-translations.js (1)
22-57: The parser implementation is adequate for the actual content ofi18n/en.po.The file contains only simple single-line
msgid/msgstrpairs with no plural forms (msgid_plural,msgstr[n]), context entries, or multi-line msgid continuations. The state machine correctly handles this structure.Likely an incorrect or invalid review comment.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@client/test-translation.json`:
- Around line 400-403: Update the translation entry for USERNAME_LOG_TITL by
correcting the article from "an username" to "a username" in the source
i18n/en.po (the msgid/msgstr for USERNAME_LOG_TITL), then regenerate the JSON
translations so client/test-translation.json reflects the corrected string
("enter valid email address, a username or a phone number"); ensure the change
appears under the "USERNAME_LOG_TITL" key.
♻️ Duplicate comments (1)
client/test-translation.json (1)
386-390: Grammar fix has been applied.The past review comment regarding "Have you forgot your password?" has been addressed—this now correctly reads "Have you forgotten your password?".
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
client/components/password-reset/__snapshots__/password-reset.test.js.snapis excluded by!**/*.snap
📒 Files selected for processing (2)
client/test-translation.jsoni18n/en.po
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Tests and Coverage
🔇 Additional comments (2)
i18n/en.po (1)
462-463: LGTM!Good grammar fix—"Have you forgotten" is the correct past participle form.
client/test-translation.json (1)
1-594: Auto-generated translation file looks good overall.The structure is consistent, multi-line strings are properly escaped, and template variables are preserved correctly. The generation from
i18n/en.poappears to be working as intended.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
7aa0e66 to
c5f2176
Compare
This PR implements automatic generation of test-translation.json from .po files as requested in #902.
Changes:
scripts/generate-test-translations.jsto parse .po files and extract translationsTesting:
Closes #902