Skip to content

Commit 838b245

Browse files
committed
feat(transloco): allow to provide multiple scopes via provideTranslocoScopes
1 parent 3be3f48 commit 838b245

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

apps/transloco-playground/src/app/lazy-multiple-scopes/lazy-multiple-scopes.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { TranslocoModule, provideTranslocoScope } from '@jsverse/transloco';
77
templateUrl: './lazy-multiple-scopes.component.html',
88
styleUrls: ['./lazy-multiple-scopes.component.scss'],
99
providers: [
10-
provideTranslocoScope({ scope: 'admin-page', alias: 'AdminPageAlias' }),
11-
provideTranslocoScope({ scope: 'lazy-page', alias: 'LazyPageAlias' }),
10+
provideTranslocoScope({ scope: 'admin-page', alias: 'AdminPageAlias' }, { scope: 'lazy-page', alias: 'LazyPageAlias' }),
1211
],
1312
standalone: true,
1413
imports: [TranslocoModule],

docs/docs/tools/scope-lib-extractor.mdx

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ import {provideTranslocoScope} from "./transloco.providers";
5656
export class CoreModule {}
5757
```
5858

59+
We also can provide several scopes at once:
60+
61+
```ts title="core.module.ts"
62+
import {provideTranslocoScope} from "./transloco.providers";
63+
@NgModule({
64+
declarations: [CoreComponent],
65+
providers: [provideTranslocoScope('core', { scope: 'shared', alias: 'sharedAlias' })],
66+
imports: [TranslocoModule]
67+
})
68+
export class CoreModule {}
69+
```
70+
5971
Now, we can use the scope in our component:
6072

6173
```ts title="lib-core.component.html"

libs/transloco/src/lib/transloco.providers.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ export function provideTranslocoLoader(loader: Type<TranslocoLoader>) {
7676
]);
7777
}
7878

79-
export function provideTranslocoScope(scope: TranslocoScope) {
80-
return {
79+
export function provideTranslocoScope(...scopes: TranslocoScope[]) {
80+
return scopes.map((scope) => ({
8181
provide: TRANSLOCO_SCOPE,
8282
useValue: scope,
8383
multi: true,
84-
};
84+
}));
8585
}
8686

8787
export function provideTranslocoLoadingTpl(content: Content) {

0 commit comments

Comments
 (0)