🐛 fix invalid language tag when passing locale argument to iframe
parent
2d686a8533
commit
5a0fbe1bad
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue