2

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 1

2

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
  }
]
Sign up to request clarification or add additional context in comments.

2 Comments

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.
nice... I'll try this ml route setting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.