Abd*_*fiz 3 multilingual routes angular
是否有像 angular 7 中的 laravel 中间件或如何通过路由设置站点的语言?( https://example.com/en/about , https://example.com/de/about )
PS目前我正在使用这种方法进行多语言。
您可以subscribe访问路由器事件,并NavigationStart在您提到的 translationService 方法中更改使用的语言,但我强烈建议您使用ngx-translate
this.router.events.subscribe((event: any): void => {
if (event instanceof NavigationStart) {
/* You should parse for the language code in the route
here and use it in the following line. Also make sure that the parsed
language code is an actual language code */
this.translationService.use(languageCode).then(() => // do your stuff);
}
});
Run Code Online (Sandbox Code Playgroud)