Skip to content

Commit

Permalink
feat(transloco): allow to provide multiple scopes via `provideTranslo…
Browse files Browse the repository at this point in the history
…coScopes`
  • Loading branch information
EricPoul committed Apr 19, 2024
1 parent 3be3f48 commit a016d48
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { TranslocoModule, provideTranslocoScope } from '@jsverse/transloco';
templateUrl: './lazy-multiple-scopes.component.html',
styleUrls: ['./lazy-multiple-scopes.component.scss'],
providers: [
provideTranslocoScope({ scope: 'admin-page', alias: 'AdminPageAlias' }),
provideTranslocoScope({ scope: 'lazy-page', alias: 'LazyPageAlias' }),
provideTranslocoScope({ scope: 'admin-page', alias: 'AdminPageAlias' }, { scope: 'lazy-page', alias: 'LazyPageAlias' }),
],
standalone: true,
imports: [TranslocoModule],
Expand Down
15 changes: 15 additions & 0 deletions docs/docs/lazy-load/scope-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ export const TODO_ROUTES: Route = {

```

We also can provide several scopes at once:

```ts title="core.module.ts"
import { Route } from '@angular/router';
import {provideTranslocoScope} from "./transloco.providers";

export const TODO_ROUTES: Route = {
path: '',
loadComponent: () => import('./todos.component').then((TodosComponent) => TodosComponent),
providers: [
provideTranslocoScope('todos', { scope: 'shared', alias: 'sharedAlias' }),
],
};
```

</TabItem>

<TabItem value="NgModule">
Expand Down
6 changes: 3 additions & 3 deletions libs/transloco/src/lib/transloco.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ export function provideTranslocoLoader(loader: Type<TranslocoLoader>) {
]);
}

export function provideTranslocoScope(scope: TranslocoScope) {
return {
export function provideTranslocoScope(...scopes: TranslocoScope[]) {
return scopes.map((scope) => ({
provide: TRANSLOCO_SCOPE,
useValue: scope,
multi: true,
};
}));
}

export function provideTranslocoLoadingTpl(content: Content) {
Expand Down

0 comments on commit a016d48

Please sign in to comment.