I'm learning Angular v.5 + Express, and I want to translate application to 2 languages using Angular i18n tool. I want my url to contain the language I'm using as follows: mysite.com/en/controller/...
My idea is to use AOT compiler, according to the guideline. Then, serve corresponding folder by Express. So, as a result I will have 2 built versions of my application, each in its own directory.
The problem is that I need to define base url in index.html file
<head>
<meta charset="utf-8">
<title>Title</title>
<base href="/en/">
...
</head>
And the URL depends on the current language. What I expected is that I can do something like
<base i18n href="/en/">
and then specify alternative path inside my translation file. However, this does not work. Am I doing something wrong? What is correct way to use i18n with AngularJS5 with such URL pattern?
A nice solution could be to use ngx-translate (which is the same than angular-translate for angularJS.
Ngx-translate have a plugin for you need :
Localize Router by @meeroslav: An implementation of routes localization for Angular. If you need localized urls (for example /fr/page and /en/page).
Ngx-translate link : https://github.com/ngx-translate/core
Here is the plugin link : https://github.com/Greentube/localize-router
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With