Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular localized base URL

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?

like image 966
alvis Avatar asked Sep 14 '26 23:09

alvis


1 Answers

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

like image 187
Leasye Avatar answered Sep 16 '26 12:09

Leasye