1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix(locale) Add navigator.userLanguage fallback for IE11.

This commit is contained in:
Dave Dunkin 2018-10-24 08:20:50 -07:00
parent d471abbbb0
commit 141faf78ba

View File

@ -18,15 +18,19 @@ export default class ShowUserComponent extends React.Component {
componentDidMount() { componentDidMount() {
this.props.fetchUser(); this.props.fetchUser();
// find default locale and add it in choices if not present // find default locale and add it in choices if not present
let locale = navigator.language; const locale = navigator.language || navigator.userLanguage;
let found = this.possibleLocales.find(l => l.value === locale); let found = this.possibleLocales.find(l => l.value === locale);
if (!found) { if (!found) {
this.possibleLocales.push({ value: locale, image: 'unknown-locale' }); this.possibleLocales.push({ value: locale, image: 'unknown-locale' });
} }
} }
getLocale() {
return (this.props.location && this.props.location.locale) || navigator.language || navigator.userLanguage;
}
updateLocale() { updateLocale() {
const locale = (this.props.location && this.props.location.locale) || navigator.language; const locale = this.getLocale();
let index = this.possibleLocales.findIndex(v => v.value === locale); let index = this.possibleLocales.findIndex(v => v.value === locale);
index = (index + 1) % this.possibleLocales.length; index = (index + 1) % this.possibleLocales.length;
this.props.updateSettingLocation('locale', this.possibleLocales[index].value); this.props.updateSettingLocation('locale', this.possibleLocales[index].value);
@ -34,7 +38,7 @@ export default class ShowUserComponent extends React.Component {
render() { render() {
const email = this.props.profile ? this.props.profile.email : ''; const email = this.props.profile ? this.props.profile.email : '';
const locale = (this.props.location && this.props.location.locale) || navigator.language; const locale = this.getLocale();
let foundLocale = this.possibleLocales.find(l => l.value === locale); let foundLocale = this.possibleLocales.find(l => l.value === locale);
const imageUrl = email ? this.props.profile.imageUrl : 'public/unknown-user.png'; const imageUrl = email ? this.props.profile.imageUrl : 'public/unknown-user.png';
const imageLocale = foundLocale ? `public/${foundLocale.image}.png` : `public/unknown-locale.png`; const imageLocale = foundLocale ? `public/${foundLocale.image}.png` : `public/unknown-locale.png`;