Skip to content

Commit

Permalink
Merge pull request #438 from jniederm/locale-recognition
Browse files Browse the repository at this point in the history
Locale language-country separator may be '_' too
  • Loading branch information
mareklibra authored Nov 27, 2017
2 parents b6693de + 6e46a6f commit 11fd010
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/intl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function getBrowserLocale (): ?string {
}

function getLocaleFromUrl (): ?string {
const localeMatch = /locale=([\w-]{2,})/.exec(window.location.search)
const localeMatch = /locale=(\w{2}([-_]\w{2})?)/.exec(window.location.search)
if (localeMatch === null) {
return null
}
Expand All @@ -56,7 +56,7 @@ function getLocaleFromUrl (): ?string {
}

function coerceToSupportedLocale (locale: string): ?string {
if (locale === 'en' || locale.startsWith('en-')) {
if (/^en/.test(locale)) {
return 'en'
}
if (getSupportedTranslatedLocales().has(locale)) {
Expand All @@ -79,7 +79,7 @@ function getSupportedTranslatedLanguageOnlyLocales (): {[string]: string} {
}

function getLocaleLanguage (locale: string): string {
return locale.split('-')[0]
return locale.split(/[-_]/)[0]
}

/**
Expand Down

0 comments on commit 11fd010

Please sign in to comment.