🐛 fix invalid language tag when passing locale argument to iframe

pull/232/head
Johan Girod 2018-05-14 10:47:20 +02:00
parent 2d686a8533
commit 5a0fbe1bad
2 changed files with 16 additions and 4 deletions

View File

@ -1,14 +1,13 @@
import { I18nextProvider } from 'react-i18next'
import i18next from 'i18next'
import queryString from 'query-string'
import { getIframeOption } from './utils'
import { getIframeOption, parseDataAttributes } from './utils'
import enTranslations from './locales/en.yaml'
let lang =
getIframeOption('lang') ||
queryString.parse(location.search)['lang'] ||
sessionStorage['lang'] ||
parseDataAttributes(sessionStorage['lang']) ||
'fr'
sessionStorage['lang'] = lang

View File

@ -1,8 +1,21 @@
export let capitalise0 = name => name[0].toUpperCase() + name.slice(1)
export let getUrl = () => window.location.href.toString()
export let parseDataAttributes = value =>
value === 'undefined'
? undefined
: value === null
? null
: !isNaN(value)
? +value
: /* value is a normal string */
value
export let getIframeOption = optionName => {
let url = getUrl(),
hasOption = url.includes(optionName + '=')
return hasOption && url.split(optionName + '=')[1].split('&')[0]
return parseDataAttributes(
hasOption && url.split(optionName + '=')[1].split('&')[0]
)
}