Skip to content

Commit

Permalink
fix(locales): use standard lang code
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed May 16, 2018
1 parent 701d0a1 commit 7a901ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/_helpers/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ export function i18nLoader (
const namespaces = Object.keys(locales)
const instance = i18n
.init({
lng: browser.i18n.getUILanguage().replace('-', '_'),
lng: browser.i18n.getUILanguage(),
fallbackLng: 'en',
debug: process.env.NODE_ENV === 'development',
saveMissing: false,
load: 'currentOnly',

defaultNS: defaultNS || namespaces[0] || 'translation',

whitelist: ['en', 'zh_CN', 'zh_TW'],
whitelist: ['en', 'zh-CN', 'zh-TW'],

interpolation: {
escapeValue: false, // not needed for react!!
},

resources: namespaces.reduce((res, ns) => {
res.zh_CN[ns] = mapValues(locales[ns], x => x.zh_CN)
res.zh_TW[ns] = mapValues(locales[ns], x => x.zh_TW)
res['zh-CN'][ns] = mapValues(locales[ns], x => x.zh_CN)
res['zh-TW'][ns] = mapValues(locales[ns], x => x.zh_TW)
res.en[ns] = mapValues(locales[ns], x => x.en)
return res
}, { zh_CN: {}, zh_TW: {}, en: {} }),
}, { 'zh-CN': {}, 'zh-TW': {}, en: {} }),

}, cb)

Expand Down
8 changes: 4 additions & 4 deletions src/app-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { DeepReadonly } from '@/typings/helpers'
import { getALlDicts } from './dicts'
import { getAllContextMenus } from './context-menus'

const langUI = (browser.i18n.getUILanguage() || 'en').replace('-', '_')
const langCode = /^zh_CN|zh_TW|en$/.test(langUI)
? langUI === 'zh_HK'
? 'zh_TW'
const langUI = (browser.i18n.getUILanguage() || 'en')
const langCode = /^zh-CN|zh-TW|en$/.test(langUI)
? langUI === 'zh-HK'
? 'zh-TW'
: langUI
: 'en'

Expand Down

0 comments on commit 7a901ec

Please sign in to comment.