feat(transloco): expose activeLang signal on TranslocoService#911
feat(transloco): expose activeLang signal on TranslocoService#911shaharkazaz merged 1 commit intomasterfrom
Conversation
Adds a `Signal<string>` property `activeLang` derived from the internal `lang` BehaviorSubject via `toSignal` with `requireSync: true`, enabling signal-based reactivity (e.g. inside `computed` or `linkedSignal`) without subscribing to `langChanges$`.
📝 WalkthroughWalkthroughA new public Changes
Possibly related issues
Fun fact: Did you know? The term "i18n" (a numeronym for "internationalization") follows a naming pattern where the first and last letters of a word are kept, with the number of letters in between replacing the middle—making "a11y" (accessibility) its equally important companion in creating globally inclusive software! 🌍 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
@jsverse/transloco
@jsverse/transloco-locale
@jsverse/transloco-messageformat
@jsverse/transloco-optimize
@jsverse/transloco-persist-lang
@jsverse/transloco-persist-translations
@jsverse/transloco-preload-langs
@jsverse/transloco-schematics
@jsverse/transloco-scoped-libs
@jsverse/transloco-utils
@jsverse/transloco-validator
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
libs/transloco/src/lib/tests/service/activeLang.spec.ts (1)
9-13: Optional: add one custom-config default language assertion.A small extra case with
createService({ defaultLang: 'es' })would strengthen regression coverage for initialization from config (not only the default test fixture).
Fun i18n fact: in German, “language” is Sprache.Suggested test addition
+ it(`GIVEN a service initialized with a custom default language + WHEN activeLang is read + THEN it should return that configured language`, () => { + service = createService({ defaultLang: 'es' }); + expect(service.activeLang()).toBe('es'); + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libs/transloco/src/lib/tests/service/activeLang.spec.ts` around lines 9 - 13, Add a test that initializes the Transloco service with a custom config and asserts the active language: call createService({ defaultLang: 'es' }) and then expect(service.activeLang()).toBe('es'); place this in the same spec (activeLang.spec.ts) alongside the existing default-language test to cover initialization-from-config paths and reference the createService helper and activeLang() method when locating where to add the assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@libs/transloco/src/lib/tests/service/activeLang.spec.ts`:
- Around line 9-13: Add a test that initializes the Transloco service with a
custom config and asserts the active language: call createService({ defaultLang:
'es' }) and then expect(service.activeLang()).toBe('es'); place this in the same
spec (activeLang.spec.ts) alongside the existing default-language test to cover
initialization-from-config paths and reference the createService helper and
activeLang() method when locating where to add the assertion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1f054855-0221-4fd3-92a3-fc7e5ad6c1f0
📒 Files selected for processing (2)
libs/transloco/src/lib/tests/service/activeLang.spec.tslibs/transloco/src/lib/transloco.service.ts
Adds a
Signal<string>propertyactiveLangderived from the internallangBehaviorSubject viatoSignalwithrequireSync: true, enabling signal-based reactivity (e.g. insidecomputedorlinkedSignal) without subscribing tolangChanges$.PR Checklist
PR Type
What kind of change does this PR introduce?
Summary by cubic
Expose
activeLangas aSignal<string>onTranslocoServiceto enable signal-based reactivity of the current language (e.g., incomputedorlinkedSignal) without subscribing tolangChanges$.Written for commit 140ad2b. Summary will update on new commits.
Summary by CodeRabbit
Release Notes
New Features
Tests