-
-
Notifications
You must be signed in to change notification settings - Fork 301
Automate language names in en.json with Weblate API, native names, and regional disambiguation #1188
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: main
Are you sure you want to change the base?
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the WalkthroughThis PR introduces an automated workflow to sync language names from Weblate into the English translation file. A new Python script fetches translation completion data from the Weblate API, validates locale codes from existing locale files, and updates frontend/locales/en.json with formatted language names (e.g., "Spanish (español)"), including only languages with 80%+ completion. A GitHub Actions workflow orchestrates this process, detecting changes and creating pull requests when updates occur. Changes
Sequence Diagram(s)sequenceDiagram
participant GitHub as GitHub Event
participant Actions as GitHub Actions
participant Script as update_language_names.py
participant Weblate as Weblate API
participant FileSystem as File System
participant PR as Pull Request
GitHub->>Actions: Push to main / workflow_dispatch
activate Actions
Actions->>FileSystem: Checkout code & setup Python 3.8
Actions->>FileSystem: Install dependencies (babel, requests)
Actions->>Script: Execute script
activate Script
Script->>FileSystem: Read frontend/locales/*.json
Script->>Script: Validate locale codes
Script->>Weblate: Fetch translation completion data
activate Weblate
Weblate-->>Script: Return paginated translation data
deactivate Weblate
Script->>Script: Merge languages with 80%+ completion
Script->>Script: Format names as "English (Native)"
Script->>FileSystem: Load frontend/locales/en.json
Script->>FileSystem: Update languages mapping
Script->>FileSystem: Save en.json with changes
Script-->>Actions: Return status
deactivate Script
Actions->>FileSystem: Diff frontend/locales/en.json
alt Changes Detected
Actions->>PR: Create PR (automation/update-language-file → main)
PR-->>Actions: PR created
else No Changes
Actions->>Actions: Log: up-to-date
end
deactivate Actions
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Security Recommendations
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
Co-authored-by: katosdev <7927609+katosdev@users.noreply.github.com>
|
@copilot This causes issues with a couple of things.
|
…d completion threshold Co-authored-by: katosdev <7927609+katosdev@users.noreply.github.com>
Co-authored-by: katosdev <7927609+katosdev@users.noreply.github.com>
All feedback addressed in commits b735ad1 and f3e817e:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
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: 2
🧹 Nitpick comments (5)
.github/workflows/update-languages/requirements.txt (1)
1-2: Consider pinning dependency versions for security and reproducibility.Unpinned dependencies can introduce supply chain risks and cause unexpected breakages when new versions are released. For CI workflows, it's recommended to pin specific versions (or at minimum, set lower bounds).
🔎 Suggested fix
-babel -requests +babel>=2.12.0,<3.0 +requests>=2.31.0,<3.0Alternatively, use exact pins like
babel==2.16.0for maximum reproducibility. You can determine current stable versions and update periodically..github/scripts/update_language_names.py (3)
98-103: Improve exception handling per static analysis hints.The broad
Exceptioncatch andlogging.errorcould be improved. Uselogging.exceptionto include the stack trace for debugging unexpected errors.🔎 Suggested fix
except requests.exceptions.RequestException as e: logging.warning("Failed to fetch from Weblate API: %s", e) return None except Exception as e: - logging.error("Unexpected error fetching Weblate data: %s", e) + logging.exception("Unexpected error fetching Weblate data: %s", e) return NoneWhile catching broad
Exceptionis generally discouraged, it's acceptable here as a fallback for unexpected API response parsing issues, and the function gracefully returnsNoneto allow Babel fallback.
197-202: Uselogging.exceptionfor better error diagnostics.Per static analysis,
logging.exceptionautomatically includes the stack trace, which is helpful for debugging file I/O issues.🔎 Suggested fix
except (IOError, json.JSONDecodeError) as e: - logging.error("Failed to load %s: %s", EN_JSON_PATH, e) + logging.exception("Failed to load %s: %s", EN_JSON_PATH, e) return {}
214-216: Uselogging.exceptionbefore exiting on save failure.This would provide the full stack trace in CI logs for debugging.
🔎 Suggested fix
except IOError as e: - logging.error("Failed to save %s: %s", EN_JSON_PATH, e) + logging.exception("Failed to save %s: %s", EN_JSON_PATH, e) sys.exit(1).github/workflows/update-language-names.yml (1)
26-31: Upgrade Python version for security updates.Python 3.8 reached end-of-life on October 7, 2024 and no longer receives security patches. Upgrade to Python 3.11 or 3.12 to maintain security coverage.
- name: Set up Python uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 with: - python-version: '3.8' + python-version: '3.11' cache: 'pip' cache-dependency-path: .github/workflows/update-languages/requirements.txt
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.github/scripts/update_language_names.py.github/workflows/update-language-names.yml.github/workflows/update-languages/requirements.txt.gitignorefrontend/locales/en.json
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-12T07:01:33.815Z
Learnt from: katosdev
Repo: sysadminsmedia/homebox PR: 19
File: backend/app/api/handlers/v1/v1_ctrl_reporting.go:28-28
Timestamp: 2024-10-12T07:01:33.815Z
Learning: The user "katosdev" prefers responses that are light-hearted and acknowledges the helpfulness of the bot in identifying issues in PRs.
Applied to files:
.github/scripts/update_language_names.py
🪛 Ruff (0.14.10)
.github/scripts/update_language_names.py
96-96: Consider moving this statement to an else block
(TRY300)
101-101: Do not catch blind exception: Exception
(BLE001)
102-102: Use logging.exception instead of logging.error
Replace with exception
(TRY400)
201-201: Use logging.exception instead of logging.error
Replace with exception
(TRY400)
215-215: Use logging.exception instead of logging.error
Replace with exception
(TRY400)
⏰ 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). (14)
- GitHub Check: End-to-End Playwright Tests / E2E Playwright Testing 4/4
- GitHub Check: Frontend Tests / Integration Tests PGSQL 17
- GitHub Check: End-to-End Playwright Tests / E2E Playwright Testing 1/4
- GitHub Check: End-to-End Playwright Tests / E2E Playwright Testing 2/4
- GitHub Check: Frontend Tests / Integration Tests PGSQL 16
- GitHub Check: End-to-End Playwright Tests / E2E Playwright Testing 3/4
- GitHub Check: Frontend Tests / Integration Tests PGSQL 15
- GitHub Check: Backend Server Tests / Go
- GitHub Check: build (linux/arm64, ubuntu-24.04-arm)
- GitHub Check: build (linux/amd64, ubuntu-latest)
- GitHub Check: build (linux/arm64, ubuntu-24.04-arm)
- GitHub Check: build (linux/amd64, ubuntu-latest)
- GitHub Check: build (linux/amd64, ubuntu-latest)
- GitHub Check: build (linux/arm64, ubuntu-24.04-arm)
🔇 Additional comments (9)
.gitignore (1)
70-71: LGTM!Standard Python bytecode ignore patterns correctly added. These prevent committing cache files generated by the new Python automation script.
frontend/locales/en.json (1)
523-563: Overall language section looks good.The format "English (Native)" aligns with PR objectives, alphabetical ordering is maintained, and special handling for
ar-AAis included. The automation script output appears consistent..github/workflows/update-language-names.yml (2)
21-24: Good security practice: Actions are pinned to commit SHAs.Using commit SHAs instead of version tags prevents supply chain attacks where a malicious actor could update a tag to point to compromised code. Well done! 🔒
49-66: Workflow PR creation looks well-configured.The workflow correctly:
- Uses a dedicated branch (
automation/update-language-file)- Includes a descriptive PR body
- Only modifies
frontend/locales/en.json- Uses
GITHUB_TOKEN(appropriate for this use case).github/scripts/update_language_names.py (5)
18-22: Good security practices for external API calls.The script correctly uses:
- Timeout for HTTP requests (prevents hanging)
- Hardcoded API URL (no injection risk)
- No authentication secrets in code (Weblate API is public)
163-168: Good validation to prevent malformed keys.This check addresses the PR objective to prevent committing malformed keys like "languages.el-GR". The validation correctly rejects locale codes containing dots or the "languages." prefix.
245-274: Logic correctly preserves existing entries and enforces completion threshold.The implementation satisfies the PR requirements:
- Skips locales already in
languages(never removes)- Enforces >=80% completion threshold when Weblate data is available
- Falls back gracefully when Weblate data is unavailable
276-277: Alphabetical sorting maintains consistent JSON output.This ensures idempotent behavior and cleaner diffs when the automation runs.
290-322: Main function has clear flow with proper exit codes.The script correctly:
- Exits with code 1 on critical failures
- Exits with code 0 on success (whether changes were made or not)
- Logs progress at each stage for CI visibility
frontend/locales/en.json
Outdated
| "pt-BR": "Portuguese (português)", | ||
| "pt-PT": "Portuguese (português)", |
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.
Duplicate display names may cause user confusion.
Both pt-BR and pt-PT display as "Portuguese (português)", making them indistinguishable in the language selector. Consider adding region qualifiers like "Portuguese - Brazil (português)" and "Portuguese - Portugal (português)" to help users select the correct variant.
🤖 Prompt for AI Agents
In frontend/locales/en.json around lines 545-546, the display names for "pt-BR"
and "pt-PT" are identical ("Portuguese (português)"), which makes them
indistinguishable in the UI; update the values to include region qualifiers
(e.g., "Portuguese — Brazil (português)" and "Portuguese — Portugal (português)"
or similar phrasing) so each locale string is unique and clearly indicates the
country variant in the language selector.
frontend/locales/en.json
Outdated
| "zh-CN": "Chinese (中文)", | ||
| "zh-HK": "Chinese (中文)", | ||
| "zh-MO": "Chinese (中文)", | ||
| "zh-TW": "Chinese (中文)" |
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.
Chinese variants have identical display names.
All four Chinese variants (zh-CN, zh-HK, zh-MO, zh-TW) display as "Chinese (中文)", which could confuse users trying to select a specific regional variant. Consider adding region identifiers (e.g., "Chinese - Simplified (中文)" for zh-CN, "Chinese - Traditional (中文)" for zh-TW).
🤖 Prompt for AI Agents
In frontend/locales/en.json around lines 559-562, the four Chinese locale
entries all use the identical display name "Chinese (中文)"; update each key to a
distinct, region-aware label (for example: zh-CN -> "Chinese - Simplified (中文)",
zh-TW -> "Chinese - Traditional (中文)", zh-HK -> "Chinese - Traditional (香港/中文)"
or "Chinese - Traditional (中文, HK)", zh-MO -> "Chinese - Traditional (澳門/中文)" or
similar) so users can distinguish regional variants; keep the native script (中文)
in each label and ensure wording is consistent with existing UI style.
|
As a note, the current changes are going to result in things being "English (English) (English (English)) because of the way the front-end works. If I remember how we did it correctly. |
|
@copilot In frontend/locales/en.json around lines 545-546, the display names for "pt-BR" Further, In frontend/locales/en.json around lines 559-562, the four Chinese locale |
Oh really? 🤔 |
|
We pull the current languages translation of the langauges for the first part Change your language to Ukrainian to see this effect really well in the demo. |
…rity Co-authored-by: katosdev <7927609+katosdev@users.noreply.github.com>
Fixed in commit 6f77eae: Portuguese variants now distinguishable:
Chinese variants now distinguishable with region labels:
Script updated to automatically apply these region qualifiers for future updates. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Good call out. This may cause us a few issues with the automation plan under #307 then. CC @tonyaellie |
What type of PR is this?
What this PR does / why we need it:
When new languages are added via Weblate, language names must be manually added to
frontend/locales/en.jsonfor proper display. This automation eliminates that manual step by querying Weblate's API and using native language names with regional disambiguation for variants.Implementation
Python Script (
.github/scripts/update_language_names.py)GitHub Actions Workflow (
.github/workflows/update-language-names.yml)mainor manual dispatchautomation/update-language-filepeter-evans/create-pull-request(same as update-currencies workflow)Current Changes
Example
When
hi-IN.jsonis added with >=80% completion:{ "languages": { "hi-IN": "Hindi (हिन्दी)" // ← Auto-added by workflow with native name } }Special notes for your reviewer:
Follows exact pattern of
update-currencies.ymlworkflow. Weblate API integration provides completion percentage filtering and native language names. Script gracefully handles API unavailability by falling back to Babel library. All locale code validation prevents malformed entries. Regional variants for Portuguese and Chinese are automatically disambiguated to ensure clarity in the UI language selector.Testing
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.