Skip to content

🌐 Added check for empty keys in context.json for i18n#27171

Merged
troyciesco merged 1 commit intomainfrom
i18n-context-ci
Apr 7, 2026
Merged

🌐 Added check for empty keys in context.json for i18n#27171
troyciesco merged 1 commit intomainfrom
i18n-context-ci

Conversation

@troyciesco
Copy link
Copy Markdown
Contributor

@troyciesco troyciesco commented Apr 6, 2026

no ref

  • We have CI checks to make sure that new i18n keys are added to context.json when they're generated, but there's no requirement to add any actual explanation for the key
  • This fixes that. When generate-context.js runs locally it will log a warning, but in CI it will error
  • This will apply to any i18n strings added from here on out - existing empty strings will be backfilled in 🌐 Backfilled empty i18n context.json strings #27170 (to land before this one)

testing

  1. Add a new translatable string to any scanned source file, e.g. in apps/portal/src/: t('Some test string')
  2. Run yarn translate in ghost/i18n -- should print:
    Warning: 1 key(s) in context.json have empty descriptions. Please add context before committing.
  3. Verify the new key was added to locales/context.json with an empty value
  4. Simulate CI: run CI=true node generate-context.js in ghost/i18n -- should exit with code 1 and list the key
  5. Add a description for the key in context.json
  6. Run CI=true node generate-context.js again -- should pass
  7. Revert your test string and run yarn translate to clean up

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 17030da8-a4c8-4a17-b966-f86bdab08972

📥 Commits

Reviewing files that changed from the base of the PR and between cb416f2 and 80a4771.

📒 Files selected for processing (1)
  • ghost/i18n/generate-context.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • ghost/i18n/generate-context.js

Walkthrough

Adds validation to the translation context generation script that scans orderedContext for keys whose values are empty or whitespace-only and collects them as emptyKeys. After the existing "context.json out of date" check and before writing context.json, the script reports these keys: in CI (process.env.CI) it logs an error listing the keys and exits with code 1; outside CI it logs a warning and continues. The updated context.json is still written via fs.writeFile.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a check for empty keys in context.json for i18n. It directly relates to the changeset.
Description check ✅ Passed The description comprehensively explains the purpose, behavior (warning vs error in CI), testing steps, and dependency on another PR. It is directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch i18n-context-ci

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.

@troyciesco troyciesco requested a review from 9larsons April 6, 2026 12:11
@troyciesco troyciesco changed the title Added check for empty keys in context.json for i18n 🌐 Added check for empty keys in context.json for i18n Apr 6, 2026
@troyciesco troyciesco marked this pull request as ready for review April 6, 2026 22:29
Copy link
Copy Markdown
Contributor

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ghost/i18n/generate-context.js`:
- Line 37: The empty-keys check in the computation of emptyKeys uses strict
equality to an empty string and misses values that are whitespace-only; update
the predicate used when filtering orderedContext to trim the value before
checking emptiness (e.g., coerce missing values to '' then call .trim()) so that
keys whose values are only whitespace are considered empty; update the filter
that defines emptyKeys (reference the orderedContext variable and the emptyKeys
constant) to use the trimmed value check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cac0e1b7-ebf0-47d4-a0be-49c84aea0118

📥 Commits

Reviewing files that changed from the base of the PR and between fcd24d3 and cb416f2.

📒 Files selected for processing (1)
  • ghost/i18n/generate-context.js

@troyciesco troyciesco requested a review from rob-ghost April 7, 2026 01:01
troyciesco added a commit that referenced this pull request Apr 7, 2026
no ref

- backfills empty i18n context hints in `context.json`
- future PR will prevent empty hints from being added
(#27171)
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 7, 2026

@troyciesco troyciesco merged commit c7ec0f8 into main Apr 7, 2026
39 checks passed
@troyciesco troyciesco deleted the i18n-context-ci branch April 7, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant