Core: URL update while changing the language

Created on 18 Jan 2018  路  1Comment  路  Source: ngx-translate/core

I'm submitting a

[ ] feature request

Current behavior
When I change language using a button click on UI , Its working amazing but the URL is not at all changing to current language.
Lets say I change the language to ru , the URL still remain same ( htttp://localhost:4200 )

Expected/desired behavior

It will be really nice If we can get the ability to manipulate the URL as traditional websites to something like, depending on the language we select through UI.

http://localhost:4200/en for English,
http://localhost:4200/ru for Russion .. and so on.

I thought of handle it using angular routing but managing it with routing will be a real mess to handlle when the project scales.

  • ngx-translate version: 9.0.2

  • Angular version: 5.0.0

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

Most helpful comment

In general I think this would be hard to implement as websites all have a different convention of representing the chosen language in the URL.

You can do it yourself by subscribing to language change events and then modifying the current url to reflect the chosen language using the Location object in the angular/common package:

translate.onLangChange().subscribe(trans => { const path = this.location.path(); const modified_path = change path to reflect chosen language (trans.lang) this.location.replaceState(modified_path); })

>All comments

In general I think this would be hard to implement as websites all have a different convention of representing the chosen language in the URL.

You can do it yourself by subscribing to language change events and then modifying the current url to reflect the chosen language using the Location object in the angular/common package:

translate.onLangChange().subscribe(trans => { const path = this.location.path(); const modified_path = change path to reflect chosen language (trans.lang) this.location.replaceState(modified_path); })

Was this page helpful?
0 / 5 - 0 ratings

Related issues

louisdoe picture louisdoe  路  3Comments

webprofusion-chrisc picture webprofusion-chrisc  路  4Comments

gmquiroga picture gmquiroga  路  3Comments

IterationCorp picture IterationCorp  路  3Comments

chris31389 picture chris31389  路  3Comments