From b744368720c0c542a1e9db801a3a5ddbaf769110 Mon Sep 17 00:00:00 2001 From: Dave Dunkin Date: Sat, 20 Oct 2018 11:09:50 -0700 Subject: [PATCH 1/3] fix(locale): Use correct US English language code. --- frontend/public/{us-US.png => en-US.png} | Bin frontend/src/component/user/show-user-component.jsx | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename frontend/public/{us-US.png => en-US.png} (100%) diff --git a/frontend/public/us-US.png b/frontend/public/en-US.png similarity index 100% rename from frontend/public/us-US.png rename to frontend/public/en-US.png diff --git a/frontend/src/component/user/show-user-component.jsx b/frontend/src/component/user/show-user-component.jsx index 4375f6bb5c..75fec9fa97 100644 --- a/frontend/src/component/user/show-user-component.jsx +++ b/frontend/src/component/user/show-user-component.jsx @@ -11,7 +11,7 @@ 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' }, ]; From d471abbbb0d1f7eeb621c320fc9656add6a01fba Mon Sep 17 00:00:00 2001 From: Dave Dunkin Date: Sat, 20 Oct 2018 11:31:24 -0700 Subject: [PATCH 2/3] fix(locale): Use navigator.language as default locale. --- frontend/src/component/user/show-user-component.jsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/frontend/src/component/user/show-user-component.jsx b/frontend/src/component/user/show-user-component.jsx index 75fec9fa97..9b2d704b9b 100644 --- a/frontend/src/component/user/show-user-component.jsx +++ b/frontend/src/component/user/show-user-component.jsx @@ -26,9 +26,7 @@ export default class ShowUserComponent extends React.Component { } updateLocale() { - const locale = this.props.location - ? this.props.location.locale - : this.possibleLocales[this.possibleLocales.length - 1]; + const locale = (this.props.location && this.props.location.locale) || navigator.language; 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 +34,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.props.location && this.props.location.locale) || navigator.language; 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`; From 141faf78ba691c92a750c4913615b7ada65ea60b Mon Sep 17 00:00:00 2001 From: Dave Dunkin Date: Wed, 24 Oct 2018 08:20:50 -0700 Subject: [PATCH 3/3] fix(locale) Add navigator.userLanguage fallback for IE11. --- frontend/src/component/user/show-user-component.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/src/component/user/show-user-component.jsx b/frontend/src/component/user/show-user-component.jsx index 9b2d704b9b..140f7af47d 100644 --- a/frontend/src/component/user/show-user-component.jsx +++ b/frontend/src/component/user/show-user-component.jsx @@ -18,15 +18,19 @@ export default class ShowUserComponent extends React.Component { 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) || navigator.language; + 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); @@ -34,7 +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) || navigator.language; + 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`;