transloco icon indicating copy to clipboard operation
transloco copied to clipboard

Bug: getBrowserCultureLang() is not working as expected in all browsers

Open MickL opened this issue 3 years ago • 6 comments

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 avatar Jul 02 '21 09:07 MickL

@MickL Can you please provide the browser versions that you tested this issue on?

shaharkazaz avatar Jul 21 '21 09:07 shaharkazaz

Latest versions everywhere:

Chrome 91.0.4472.164 Safari 14.1.1 Firefox 90.0.1

MickL avatar Jul 21 '21 12:07 MickL

This issue is still open and reproducible with current browsers and transloco/transloco-locale versions. Are there any fixes available @shaharkazaz?

dvdvnl avatar Jun 14 '23 09:06 dvdvnl

@dvdvnl Currently no. You are welcome to open a PR for it 🙂

shaharkazaz avatar Jun 18 '23 05:06 shaharkazaz

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

ld210 avatar Sep 25 '23 07:09 ld210