ngx-translate / core

The internationalization (i18n) library for Angular
MIT License
4.53k stars 578 forks source link

getBrowserCultureLang() doesn't provide the culture language #851

Open 82antu opened 6 years ago

82antu commented 6 years ago

Current behavior

with a language configuration like this: (Chrome settings):

image

the browserCultureLang returns by getBrowserCultureLang() will be just

de

since var browserCultureLang will set with window.navigator.languages[0]:

https://github.com/ngx-translate/core/blob/59bdf3c6431396a31a27c9521c5a3f300e85dd1c/projects/ngx-translate/core/src/lib/translate.service.ts#L514

where window.navigator.languages array is["de", "en-US", "en"]

Expected behavior

getBrowserCultureLang() shuold returns the selected language "en-US"

How do you think that we should fix this?

https://github.com/ngx-translate/core/blob/59bdf3c6431396a31a27c9521c5a3f300e85dd1c/projects/ngx-translate/core/src/lib/translate.service.ts#L515

list of properties allocable to browserCultureLang on line 515, could have,...maybe a different order, since, according to chrome settings in picture,

window.navigator.language should be returns and not the browserCultureLang calculated on https://github.com/ngx-translate/core/blob/59bdf3c6431396a31a27c9521c5a3f300e85dd1c/projects/ngx-translate/core/src/lib/translate.service.ts#L514

Minimal reproduction of the problem with instructions

on chrome settings, goes on section "languages" --> "Order languages based on your preference";

select "English (United States) and set the checkbox "Display Google Chrome in this language";

then add "German" (if it is not still there ) on the languages list and put it on the top of the list ("Move on the top"):

translateService.getBrowserCultureLang() will returns

"de"

Environment


ngx-translate version: 9.1.1
Angular version: 5.2.5


Browser:
- [X ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

Others:
not tried with other browser yet.

Thanks in advance            
Massimiliano-Perelli commented 6 years ago

Same issue here!

khan990 commented 6 years ago

Yes, I need it too.

rafa-suagu commented 6 years ago

+1

PhilippMeissner commented 5 years ago

bump

KyDenZ commented 4 years ago

Works with Chrome 80 : fr-FR But does not work with Safari 13.1 : fr

VladislavGulik commented 3 years ago

+1