1 | import {
|
2 | setLocaleId,
|
3 | setLocales
|
4 | } from '../index'
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export default ({
|
13 | localeId,
|
14 | locales
|
15 | }) => {
|
16 | if (!__CLIENT__) return
|
17 |
|
18 | if (typeof localeId === 'undefined' &&
|
19 | typeof __REDUX_STATE__ === 'object' &&
|
20 | typeof __REDUX_STATE__.localeId !== 'undefined'
|
21 | )
|
22 | localeId = __REDUX_STATE__.localeId
|
23 | if (typeof locales === 'undefined' &&
|
24 | typeof __REDUX_STATE__ === 'object' &&
|
25 | typeof __REDUX_STATE__.locales !== 'undefined'
|
26 | )
|
27 | locales = __REDUX_STATE__.locales
|
28 |
|
29 | if (typeof localeId === 'undefined' || typeof locales === 'undefined')
|
30 | return
|
31 |
|
32 | setLocaleId(localeId)
|
33 | setLocales(localeId, locales)
|
34 |
|
35 | if (localeId && typeof document !== 'undefined' && typeof document.cookie !== 'undefined') {
|
36 | const Cookies = require('js-cookie')
|
37 | const cookieOptions = {
|
38 | expires: 365
|
39 | }
|
40 | if (typeof process.env.SUPER_I18N_COOKIE_DOMAIN === 'string' &&
|
41 | process.env.SUPER_I18N_COOKIE_DOMAIN) {
|
42 | cookieOptions.domain = process.env.SUPER_I18N_COOKIE_DOMAIN
|
43 | }
|
44 | Cookies.set(
|
45 | process.env.SUPER_I18N_COOKIE_KEY,
|
46 | localeId,
|
47 | cookieOptions
|
48 | )
|
49 | }
|
50 | }
|