Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web app that support multiple languages. I am successfully translating the content of the app with @ngx-translate. However; I also need to translate the route link. My link look like this

www.somewebsite.com/dashboard

Now when I change the language to something like Turkish; I need the link look like

www.somewebsite.com/anasayfa

How can I achieve that easily? Any help is appreciated. Thanks in advance.

What I have tried:

Tried using
ngx-i18n-router
and
localize-router
, but it did not help.
Posted
Updated 26-Aug-18 3:16am

1 solution

This is sort of bad idea to implement, since you need to build several routes for each language. Generally i would recommend you to configure routes with languages. For example,

www.somewebsite.com/en/dashboard

and if its a differencet language then it should be,

www.somewebsite.com/es/dashboard.


However if you really want to build with different language routes then you have to do,

Create a new path : { path: ':lang/dashboard', component: dashboardComponent }

this.route.params.subscribe(params => {
            translate.use(params['lang']);
            switch (params['lang']) {
                case 'en':
                    location.replace(`index.html#/${params['lang']}/dashboard`)
                        break;
                case 'fr':
                    location.replace(`index.html#/${params['lang']}/anasayfa`);
                        break;
            }

  })
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900