I want to create the multi-language support for the website. I'm currently using ngx-translate to translate all the text . Let's way we have two urls, mypage/en/home and mypage/es/home. How can I create those language paths and route them to home component?
1 Answer
Updated based on comment:
In the routes for the router you can do something like this:
export const routes: Routes =[
{
path: 'mypage/:language/home', component: HomeComponent
}
]
This way you actually only need one route and can have as many languages as you want.
Then in your component you can do:
public constructor (
route: ActivatedRoute
){
this.language = this.route.snapshot.params['language'];
}
If you really want multiple routes, you can do something like this:
export const routes: Routes =[
{
path: 'mypage/en/home', component: HomeComponent
}
{
path: 'mypage/es/home', component: HomeComponent
}
]
2 Comments
Fwdev
I know ngx-translate my separate .json files for each language. But I want to create the language path like mypage/en/home , mypage/es/home, just want to create an extra language path, the route will detect that language path to translate accordingly.
M. Carlo Bramini
nice... I'll try this ml route setting