transloco
transloco copied to clipboard
Bug: getBrowserCultureLang() is not working as expected in all browsers
Current behavior
Using getBrowserCultureLang()
returns:
- Chrome: de-DE (correct)
- Firefox: de (wrong)
- Safari: de-de (wrong)
The problem gets worse when using transloco-locale
:
translocoLocaleService.setLocale(getBrowserCultureLang())
-> Throws "de isn't a valid locale format"
Expected behavior
Should always return correct format 'de-DE'
Minimal reproduction of the problem with instructions
import { getBrowserCultureLang } from '@ngneat/transloco';
console.log(getBrowserCultureLang());
Environment
- transloco: 2.20.1
- transloco-locale: 1.4.0
- Angular: 12.0.1
@MickL Can you please provide the browser versions that you tested this issue on?
Latest versions everywhere:
Chrome 91.0.4472.164 Safari 14.1.1 Firefox 90.0.1
This issue is still open and reproducible with current browsers and transloco/transloco-locale versions. Are there any fixes available @shaharkazaz?
@dvdvnl Currently no. You are welcome to open a PR for it 🙂
const navigator = window.navigator;
return navigator.languages ? navigator.languages.find((lang) => lang.indexOf('-') > -1 || lang.indexOf('_') > -1) : navigator.language;
... should yield consistent results across browsers. Well, at least Chrome/Firefow/Safari