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

Feature(scope): Route Title Resolver #839

Open
1 task done
Doublon opened this issue Mar 1, 2025 · 0 comments
Open
1 task done

Feature(scope): Route Title Resolver #839

Doublon opened this issue Mar 1, 2025 · 0 comments

Comments

@Doublon
Copy link

Doublon commented Mar 1, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Which Transloco package(s) will this feature affect?

Don't know / other

Is your feature request related to a problem? Please describe

Hi everyone,

I'm looking for a way to translate every tab title without duplicating the code. To solve this, I would like to create a resolver such as:

export const titleTranslationResolver: ResolveFn<string> = (route, state) => {
  console.log("titleTranslationResolver")
  if (!route.data["titleKey"]) {
    return Promise.resolve('Default title');
  }

  const transloco = inject(TranslocoService);
  return Promise.resolve(transloco.translate(route.data["titleKey"]));
};

and use it in my router:

export const routes: Routes = [
  {
    path: 'participants',
    title: titleTranslationResolver,
    pathMatch: 'full',
    loadComponent: () => import('@presentation/pages/participants-page/participants-page.component').then(m => m.ParticipantsPageComponent),
    canActivate: [ConnectedGuard],
    data: { titleKey: 'participant_list' }
  },
  { path: '',   redirectTo: 'participants', pathMatch: 'full' },
  {
    path: '**',
    title: titleTranslationResolver,
    loadComponent: () => import('@presentation/pages/not-found-page/not-found-page.component').then(m => m.NotFoundPageComponent)
  }
];

The issue with this solution is that Transloco is initialized after my routes, even with this code:

export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(),
    provideTransloco({
      config: {
        availableLangs: ['en'],
        defaultLang: 'en',
        // Remove this option if your application doesn't support changing language in runtime.
        reRenderOnLangChange: true,
        prodMode: !isDevMode(),
      },
      loader: TranslocoHttpLoader
    }),
    provideRouter(routes),
  ]
};

Image

Describe the solution you'd like

Maybe I did something wrong, but here are two potential solutions:

  • Use a native Transloco resolver for translating tabs.
  • Allow the TranslocoHttpLoader to initialize before the router.

Describe alternatives you've considered

For now I translate in every component "page" in the ngOnInit method

Additional context

No response

I would like to make a pull request for this feature

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant