turquoiseowl / i18n

Smart internationalization for ASP.NET
Other
556 stars 156 forks source link

Angular template wrong language #267

Closed markiyanharbych closed 8 years ago

markiyanharbych commented 8 years ago

Hello,

First of all I want to thank you for this good plugin :+1:

I've faced one problem on my current project.

I'm using angular and in my angular service to do the ajax calls to the server I was using the urls without the language tag ('skills/add' for example). The problem was raised when the requests started to fail when user was using the browser with some other language from the default one (so the language was set as the setting in the browser, basically for the browser menus etc.). So for example if the default language is english, but the user has Chrome with danish language then the requests are failing.

I've figure out the problem with that - somehow the browser is sending the language tag equal to da(even if the url was without the language tag so it should use en). So when you do the post call, then on begin request the code checks that the current language is da, which is not enabled, that's why it redirects to 'en' url, so the post is failing and the the GET url with the 'en' is getting requested.

The only solution I have for now is to simply add everywhere in the calls the language tag

BUT

There's the other problem I've found in the process of investigation the first one.

Using angular .html templates - the [[[]]] pieaces are translated to the language that is set in the browser, and not in the url. So on the MVC view for example the text is translated to english, but in the angular .html template it is translated to danish.

The only solution I have for now for this issue is to remove .html from the QuickUrlExclusionFilter and then also add the language tag even to the angular .html template files

I would like to know if you're familiar with this problem and maybe you have some better solutions for it

Thank you.

turquoiseowl commented 8 years ago

Your question isn't too clear to me. But just to say there is an algorithm which i18n uses to determine what the Principle Application Language will be for each HTTP request, which uses multiple inputs: URL, cookies, Accept-Language header (i.e. browser language setting) and your app's i18n default language setting.

Full details on the algorithm are given in the readme. It is then down to you to decide a strategy on how you want the Principle Application Language for each and every request to be determined by your app in terms of those inputs.

Probably the most straight-forward strategy is to put the language tag in every URL.

markiyanharbych commented 8 years ago

sorry for beeing not clear

and thenks for your reply.

'put the language tag in every URL' - this is what I already did, I just thought that maybe there's another solution. But I'm ok with this one, will move forward with this.

Thank you for a quick reply.