有没有类似角度7的laravel中间件,或者如何通过路线设置站点的语言? (https://example.com/en/about,https://example.com/de/about)
P.S。目前,我正在将this method用于多语言。
答案 0 :(得分:3)
您可以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);
}
});