1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-15 01:16:22 +02:00

Merge pull request #159 from ddunkin/locale-fixes

Locale fixes
This commit is contained in:
Ivar Conradi Østhus 2018-10-24 18:48:30 +02:00 committed by GitHub
commit 386c21cb56
2 changed files with 8 additions and 8 deletions

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -11,24 +11,26 @@ export default class ShowUserComponent extends React.Component {
};
possibleLocales = [
{ value: 'nb-NO', image: 'nb-NO' },
{ value: 'us-US', image: 'us-US' },
{ value: 'en-US', image: 'en-US' },
{ value: 'en-GB', image: 'en-GB' },
];
componentDidMount() {
this.props.fetchUser();
// 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);
if (!found) {
this.possibleLocales.push({ value: locale, image: 'unknown-locale' });
}
}
getLocale() {
return (this.props.location && this.props.location.locale) || navigator.language || navigator.userLanguage;
}
updateLocale() {
const locale = this.props.location
? this.props.location.locale
: this.possibleLocales[this.possibleLocales.length - 1];
const locale = this.getLocale();
let index = this.possibleLocales.findIndex(v => v.value === locale);
index = (index + 1) % this.possibleLocales.length;
this.props.updateSettingLocation('locale', this.possibleLocales[index].value);
@ -36,9 +38,7 @@ export default class ShowUserComponent extends React.Component {
render() {
const email = this.props.profile ? this.props.profile.email : '';
const locale = this.props.location
? this.props.location.locale
: this.possibleLocales[this.possibleLocales.length - 1].value;
const locale = this.getLocale();
let foundLocale = this.possibleLocales.find(l => l.value === locale);
const imageUrl = email ? this.props.profile.imageUrl : 'public/unknown-user.png';
const imageLocale = foundLocale ? `public/${foundLocale.image}.png` : `public/unknown-locale.png`;