Skip to content

test: Validate local files are valid - #8179

Merged
Gared merged 3 commits into
developfrom
locale_validation
Sep 5, 2026
Merged

test: Validate local files are valid#8179
Gared merged 3 commits into
developfrom
locale_validation

Conversation

@Gared

@Gared Gared commented Aug 30, 2026

Copy link
Copy Markdown
Member

This test will check for translation errors in the future and should prevent #8163

@Gared
Gared marked this pull request as ready for review August 30, 2026 12:18
Comment thread src/tests/backend-new/specs/locale-files.test.ts Fixed
Comment thread src/tests/backend-new/specs/locale-files.test.ts Fixed
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Validate locale JSON structure and translation macros

🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Validates every locale file is a JSON object containing string translations and structured
 metadata.
• Rejects unsupported translation macros and plural option names across the locale corpus.
Diagram

graph TD
  A["Vitest Runner"] --> B["Locale Test"] --> C["Locale JSON Files"] --> D["Structure Validation"]
  C --> E["Macro Validation"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Reuse the production localization parser
  • ➕ Keeps validation aligned with runtime parsing behavior
  • ➕ Avoids regex grammar drift as macro syntax evolves
  • ➖ Couples corpus tests to runtime localization internals
  • ➖ May require additional setup and less targeted failure reporting
2. Validate with a JSON schema
  • ➕ Provides a declarative contract for metadata and translation values
  • ➕ Can be reused by editors or CI tooling
  • ➖ Does not validate embedded macro syntax without custom extensions
  • ➖ Adds schema maintenance and validation dependencies

Recommendation: The focused Vitest approach is appropriate for lightweight regression prevention and clear file/key failures. If the production localization parser exposes a stable validation API, prefer it over the custom macro regex so accepted syntax has a single source of truth.

Files changed (1) +61 / -0

Tests (1) +61 / -0
locale-files.test.tsAdd corpus-wide locale file validation +61/-0

Add corpus-wide locale file validation

• Adds Vitest coverage that parses every locale JSON file and verifies its top-level object shape, metadata object, and string translation values. It also reports unsupported macros and invalid plural option names with file and translation-key context.

src/tests/backend-new/specs/locale-files.test.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Aug 30, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Italian macro remains unfixed ✓ Resolved 📎 Requirement gap ≡ Correctness
Description
The new validation records Italian's plurale macro as unsupported and then requires an empty
failure list, so this test fails while the translation that freezes Italian-configured pads remains
in the corpus. Replace plurale/uno/altro with the supported plural/one/other syntax so
the test passes and the runtime loop is removed.
Code

src/tests/backend-new/specs/locale-files.test.ts[R29-30]

+          if (!allowedMacros.has(macroName)) failures.push(`${rel}:${key}:${macroName}`);
+          if (macroName !== 'plural') continue;
Evidence
Rule 1 requires Italian-selected pads to remain responsive. The added validator permits only
plural and pushes the still-present Italian plurale macro into failures; src/locales/it.json
retains that unsupported macro, while runtime localization registers only plural and the affected
string is consumed by the pad user list.

Italian language selection does not freeze pads
src/tests/backend-new/specs/locale-files.test.ts[13-15]
src/tests/backend-new/specs/locale-files.test.ts[26-39]
src/locales/it.json[398-398]
src/static/js/vendors/html10n.ts[729-742]
src/static/js/pad_userlist.ts[568-576]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new locale validation detects the existing Italian `plurale` macro and fails, but the PR does not correct the translation responsible for the Italian pad freeze.
## Issue Context
The runtime supports `plural` with CLDR option names. Update Italian's `pad.userlist.onlineCount` from `plurale(count) uno: ... altro: ...` to `plural(count) one: ... other: ...`, preserving the Italian display text.
## Fix Focus Areas
- src/locales/it.json[398-398]
- src/tests/backend-new/specs/locale-files.test.ts[26-39]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Malformed macros evade validation ✓ Resolved 🐞 Bug ≡ Correctness
Description
The validation loop only checks strings that fully match macroRe, so malformed macro candidates
are silently skipped; existing Hungarian and Unicode locale entries pass this test even though the
runtime cannot expand them and displays the raw {[...]} markup. This prevents the test from
enforcing its stated guarantee that the locale corpus contains no unsupported macros.
Code

src/tests/backend-new/specs/locale-files.test.ts[26]

+        while ((match = macroRe.exec(value)) !== null) {
Evidence
The Hungarian corpus has a comma after plural(num), while other locales contain non-ASCII macro
syntax; none can match the new ASCII-only full macro regex, so line 26 never validates them. The
runtime also processes only regex matches and otherwise returns the original string, proving these
entries reach the UI as literal macro markup.

src/tests/backend-new/specs/locale-files.test.ts[13-35]
src/locales/hu.json[161-161]
src/locales/diq.json[162-162]
src/locales/shn.json[109-109]
src/locales/my.json[152-152]
src/static/js/vendors/html10n.ts[718-726]
src/static/js/vendors/html10n.ts[729-748]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The locale validator only inspects complete `macroRe` matches, allowing malformed or runtime-unsupported `{[...]}` expressions to pass unnoticed.
## Issue Context
The runtime uses similarly restrictive syntax and leaves unmatched macro text in the rendered translation. Scan for every macro candidate, validate that the entire candidate conforms to supported syntax, and report malformed candidates; update currently invalid locale entries so the strengthened test passes.
## Fix Focus Areas
- src/tests/backend-new/specs/locale-files.test.ts[13-39]
- src/locales/hu.json[161-161]
- src/locales/diq.json[162-162]
- src/locales/shn.json[109-109]
- src/locales/my.json[152-152]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Finding overflow, which tucks the rest behind 'View more'

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/tests/backend-new/specs/locale-files.test.ts
Comment thread src/tests/backend-new/specs/locale-files.test.ts Outdated
@Gared
Gared requested review from JohnMcLear and SamTV12345 August 30, 2026 12:22
@Gared
Gared merged commit 497114e into develop Sep 5, 2026
34 of 35 checks passed
@Gared
Gared deleted the locale_validation branch September 5, 2026 09:55
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.

3 participants