Skip to content

Conversation

@Ajay110125yadav
Copy link

This PR implements automatic generation of test-translation.json from .po files as requested in #902.

Changes:

  • Added scripts/generate-test-translations.js to parse .po files and extract translations
  • Handles both single-line and multi-line msgstr formats
  • Updated test-translation.json with complete translations from i18n/en.po
  • Fixed test that was expecting untranslated key

Testing:

  • All tests pass locally
  • yarn test -u used to update snapshots

Closes #902

- Add script to parse .po files
- Update test-translation.json with complete translations
- Fix test expecting raw key instead of translation

Closes openwisp#902
@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

📝 Walkthrough

Walkthrough

A 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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature: automating generation of test-translation.json from .po files, which is the primary objective of this PR.
Description check ✅ Passed The description covers the main changes, testing approach, and links to issue #902. While it doesn't fill all template sections, it provides sufficient detail about the implementation.
Linked Issues check ✅ Passed The PR successfully implements the core requirements from #902: it provides a script (generate-test-translations.js) to automatically extract translations from .po files, updates test-translation.json with those translations, and includes necessary grammar fixes.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #902: the new script for generation, the updated translations file, the grammar corrections in the .po file, and the test update are all in scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5f2176 and add2422.

⛔ Files ignored due to path filters (2)
  • client/components/login/__snapshots__/login.test.js.snap is excluded by !**/*.snap
  • client/components/password-reset/__snapshots__/password-reset.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • client/test-translation.json
  • i18n/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 (3)
i18n/en.po (2)

462-463: LGTM! Grammar correction applied.

The change from "Have you forgot" to "Have you forgotten" is correct—using the past participle form with the auxiliary "have."


478-478: LGTM! Grammar correction applied.

The article correction from "an username" to "a username" is correct—"username" begins with a consonant sound (/j/ as in "you").

client/test-translation.json (1)

1-594: Generated translation file looks well-structured.

The file correctly mirrors the translation entries from i18n/en.po with proper JSON structure. The msgstr values are correctly wrapped in arrays as expected by the translation system.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1393643 and 501ff39.

⛔ Files ignored due to path filters (3)
  • client/components/password-reset/__snapshots__/password-reset.test.js.snap is excluded by !**/*.snap
  • client/components/registration/__snapshots__/registration.test.js.snap is excluded by !**/*.snap
  • client/components/status/__snapshots__/status.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • client/components/status/status.test.js
  • client/test-translation.json
  • scripts/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 of i18n/en.po.

The file contains only simple single-line msgid/msgstr pairs 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.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 501ff39 and 7aa0e66.

⛔ Files ignored due to path filters (1)
  • client/components/password-reset/__snapshots__/password-reset.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • client/test-translation.json
  • i18n/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.po appears to be working as intended.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@Ajay110125yadav Ajay110125yadav force-pushed the issues/902-automate-test-translations branch from 7aa0e66 to c5f2176 Compare January 26, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Automate generation of client/test-translation.json from .po files

1 participant