Skip to content

Add i18n Support#126

Open
eric-pSAP wants to merge 13 commits into
mainfrom
i18n
Open

Add i18n Support#126
eric-pSAP wants to merge 13 commits into
mainfrom
i18n

Conversation

@eric-pSAP
Copy link
Copy Markdown
Contributor

@eric-pSAP eric-pSAP commented May 12, 2026

Adds i18n support beyond hard-coded English. Prereq: #125

Copy link
Copy Markdown
Contributor

@hyperspace-insights hyperspace-insights Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces i18n support across the notification pipeline with good test coverage, but has several correctness issues: the most critical is that cds.load() is called redundantly inside the "served" handler instead of using cds.model, meaning the "loaded" hook's recipients injection is bypassed for that model instance. Additionally, resolveEnum().toUpperCase() can throw on non-string channel values, and cds.reflect() in compile.js is inconsistent with how the rest of the codebase iterates definitions directly.

PR Bot Information

Version: 1.20.47

  • File Content Strategy: Full file content
  • Event Trigger: pull_request.opened
  • Correlation ID: 685f3a58-da82-4729-88de-7f2eec06c33d
  • LLM: anthropic--claude-4.6-sonnet

Comment thread lib/compile.js Outdated
Comment thread lib/compile.js Outdated
Comment thread cds-plugin.js Outdated
Comment thread tests/unit/lib/compile.test.js Outdated
Comment thread tests/unit/lib/compile.test.js Outdated
@eric-pSAP eric-pSAP marked this pull request as ready for review June 3, 2026 14:25
@hyperspace-insights
Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Add i18n Support for Notification Templates

New Feature

✨ Introduces internationalization (i18n) support for notification templates, moving beyond hard-coded English. Notification type templates are now generated per available locale by reading .properties files from a _i18n/ directory. Default and custom notifications also respect the current request locale from cds.context.

Changes

  • lib/compile.js: Added loadI18nBundles() to scan _i18n/i18n*.properties files and parseProperties() to parse them. notificationTypesFromModel() now generates one Templates entry per available locale (falling back to English-only if no i18n files are found). resolveI18n() now accepts a texts map instead of relying on cds.i18n. Fixed a safety guard in deliveryChannels processing to skip non-string channel values.

  • lib/utils.js: buildDefaultNotification() and buildCustomNotification() now use cds.context?.locale ?? 'en' instead of the hard-coded "en" string for property language assignment.

  • lib/build.js: Minor cleanup (trailing whitespace/comment fix).

  • tests/bookshop/_i18n/i18n_de.properties: Added German translations for the BookOrderedNotify notification type used in integration tests.

  • tests/integration/bookshop.test.js: Updated existing i18n template test to look up the English template by language key; added new tests verifying that templates for all available locales (e.g., en and de) are generated and that German translations are correctly applied.

  • tests/unit/lib/compile.test.js: Refactored i18n tests into a dedicated describe("i18n integration") block using jest.spyOn on fs instead of mocking cds.i18n. Added new test cases covering per-locale template generation, English fallback when a locale key is missing, and subtitle field resolution.

  • tests/unit/lib/utils.test.js: Added tests verifying that both default and custom notifications use the locale from cds.context when set.


  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.21.4

Copy link
Copy Markdown
Contributor

@hyperspace-insights hyperspace-insights Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces a solid i18n foundation — the locale-aware template generation and cds.context locale propagation are well-structured and well-tested. However, there are a few correctness issues to address: the English locale is not guaranteed to be included when only non-English .properties files exist, parseProperties will silently produce wrong keys on CRLF line endings, and the stray leading space before parseProperties is a minor but real inconsistency. The missing newline at end of bookshop.test.js should also be fixed.

PR Bot Information

Version: 1.21.4

  • Correlation ID: d7f82453-bf26-40a7-ae08-983ef7336615
  • File Content Strategy: Full file content
  • Event Trigger: pull_request.ready_for_review
  • LLM: anthropic--claude-4.6-sonnet

Comment thread lib/compile.js Outdated
Comment thread lib/compile.js Outdated
Comment thread lib/compile.js Outdated
Comment thread lib/compile.js Outdated
Comment thread tests/integration/bookshop.test.js Outdated
@eric-pSAP eric-pSAP requested a review from stefanrudi June 3, 2026 15:00
Comment thread lib/compile.js Outdated
Comment thread lib/compile.js Outdated
Comment thread lib/compile.js Outdated
@eric-pSAP eric-pSAP requested a review from stefanrudi June 5, 2026 09:32
Comment thread lib/compile.js Outdated
Comment thread tests/integration/bookshop.test.js
Comment thread lib/compile.js Outdated
eric-pSAP and others added 2 commits June 5, 2026 13:18
Co-authored-by: Stefan Rudi <54106627+stefanrudi@users.noreply.github.com>
@eric-pSAP eric-pSAP requested a review from stefanrudi June 5, 2026 12:17
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.

2 participants