Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(transloco): allow to provide multiple scopes via provideTranslocoScope #758

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading