Skip to content

fix(transloco): accept a scope in selectTranslateObject lang argument - #1001

Open
arturovt wants to merge 1 commit into
jsverse:masterfrom
arturovt:fix/529-select-translate-object-scope-type
Open

fix(transloco): accept a scope in selectTranslateObject lang argument#1001
arturovt wants to merge 1 commit into
jsverse:masterfrom
arturovt:fix/529-select-translate-object-scope-type

Conversation

@arturovt

@arturovt arturovt commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

At runtime selectTranslateObject already loads an unloaded scope file when you pass the scope as the third argument, but the type only allowed a plain string. That made the documented "loads the file if not loaded" behaviour unreachable without a cast when passing a { scope, loader } object.

Widen the string / string[] key overloads to accept string | TranslocoScope | TranslocoScope[], matching selectTranslate. The key-map overload is left as a plain string since that path does not support a scope.

Closes #529

Summary by CodeRabbit

  • Enhancements

    • Expanded selectTranslateObject to support scoped translations, including loading translations from unloaded scopes.
    • Added support for specifying one or multiple translation scopes when selecting translation objects.
  • Tests

    • Added coverage confirming scoped translation objects load and emit the expected results.

At runtime selectTranslateObject already loads an unloaded scope file
when you pass the scope as the third argument, but the type only allowed
a plain string. That made the documented "loads the file if not loaded"
behaviour unreachable without a cast when passing a { scope, loader }
object.

Widen the string / string[] key overloads to accept
string | TranslocoScope | TranslocoScope[], matching selectTranslate.
The key-map overload is left as a plain string since that path does not
support a scope.

Closes jsverse#529
@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 493b7e66-e109-4378-9651-0ef9f3d249cb

📥 Commits

Reviewing files that changed from the base of the PR and between f940f6f and e7836fe.

📒 Files selected for processing (2)
  • libs/transloco/src/lib/tests/service/selectTranslateObject.spec.ts
  • libs/transloco/src/lib/transloco.service.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

selectTranslateObject now accepts TranslocoScope and TranslocoScope[] values. Its implementation preserves string handling for key maps. A test verifies that an unloaded scoped translation file loads and emits the expected translation object.

Changes

Scoped translation object selection

Layer / File(s) Summary
Service scope support and validation
libs/transloco/src/lib/transloco.service.ts, libs/transloco/src/lib/tests/service/selectTranslateObject.spec.ts
selectTranslateObject accepts string and scope-based language arguments. Key-map handling casts the language value for recursive selection and translateObject. Tests cover loading and emitting an object from an unloaded scope.

Suggested reviewers: shaharkazaz

Merge Risk: ⚪ Minimal · up to e7836

This change makes already-supported scoped translation loading type-safe without changing the runtime loading mechanism. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: allowing a scope in the selectTranslateObject lang argument.
Description check ✅ Passed The description explains the current type limitation, the new overload behavior, the key-map exception, and the linked issue. It omits the repository checklist and explicit PR type and breaking-change…
Linked Issues check ✅ Passed The changes address issue #529 by enabling the documented unloaded-scope loading behavior without a type cast. The added test verifies that selectTranslateObject accepts a scope object, loads the scop…
Out of Scope Changes check ✅ Passed The changes are limited to selectTranslateObject overload typings and a focused regression test. The key-map overload remains unchanged in scope behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Description check

Explanation

The description explains the current type limitation, the new overload behavior, the key-map exception, and the linked issue. It omits the repository checklist and explicit PR type and breaking-change selections, but the main technical information is complete.

Full details: Linked Issues check

Explanation

The changes address issue #529 by enabling the documented unloaded-scope loading behavior without a type cast. The added test verifies that selectTranslateObject accepts a scope object, loads the scoped file, and emits the expected translation object.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@pkg-pr-new

pkg-pr-new Bot commented Aug 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@jsverse/transloco

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco@1001

@jsverse/transloco-keys-manager

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-keys-manager@1001

@jsverse/transloco-locale

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-locale@1001

@jsverse/transloco-messageformat

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-messageformat@1001

@jsverse/transloco-optimize

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-optimize@1001

@jsverse/transloco-persist-lang

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-persist-lang@1001

@jsverse/transloco-persist-translations

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-persist-translations@1001

@jsverse/transloco-preload-langs

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-preload-langs@1001

@jsverse/transloco-schematics

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-schematics@1001

@jsverse/transloco-scoped-libs

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-scoped-libs@1001

@jsverse/transloco-utils

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-utils@1001

@jsverse/transloco-validator

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-validator@1001

commit: e7836fe

@medbenmakhlouf medbenmakhlouf added bug Something isn't working transloco Related to the @jsverse/transloco core package area: scope Scope resolution, lazy-loaded scopes, TRANSLOCO_SCOPE labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: scope Scope resolution, lazy-loaded scopes, TRANSLOCO_SCOPE bug Something isn't working transloco Related to the @jsverse/transloco core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug(selectTranslateObject): It doesn't load the file, missing translation

2 participants