提交 d98b1ac5 编写于 作者: Q qiang

feat: cli-i18n

上级 b7e19952
describe('env', () => {
it('HBuilderX', () => {
process.env.UNI_HBUILDERX_LANGID = 'fr'
const i18n = require('../lib/index')
expect(i18n.getLocale()).toBe('fr')
})
})
const { format } = require('../lib/lang')
describe('format', () => {
it('env.lang', () => {
expect(format('zh_CN.UTF_8')).toBe('zh_CN')
})
})
const { I18n } = require('i18n')
const { format } = require('./lang')
const defaultLocale = format(process.env.UNI_HBUILDERX_LANGID || process.env.LANG)
const i18n = new I18n()
const staticCatalog = {}
// 暂时仅支持 en、zh_CN
const locales = [
'en',
// 'es',
// 'fr',
// 'zh_HK',
'zh_CN'
]
locales.forEach(item => {
// TODO 合并 HBuilderX 内置内容
staticCatalog[item] = require(`../locales/${item}.json`)
})
i18n.configure({
staticCatalog,
defaultLocale
})
module.exports = i18n
function format (lang) {
const array = lang.split(/[\.,]/)[0].split(/[_-]/)
array[0] = array[0].toLowerCase()
if (array[0] === 'zh') {
array[1] = (array[1] || 'CN').toUpperCase()
}
array.length = Math.min(array.length, 2)
return array.join('_')
}
module.exports = {
format
}
\ No newline at end of file
{}
\ No newline at end of file
{}
\ No newline at end of file
{}
\ No newline at end of file
{}
\ No newline at end of file
{}
\ No newline at end of file
{
"name": "@dcloudio/uni-cli-i18n",
"version": "0.0.1",
"description": "uni-cli-i18n",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/dcloudio/uni-app.git",
"directory": "packages/uni-cli-i18n"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "fxy060608",
"license": "Apache-2.0",
"dependencies": {
"i18n": "^0.13.3"
}
}
......@@ -746,7 +746,6 @@
"@dcloudio/uni-i18n@^2.0.0-31920210514002":
version "2.0.0-31920210514002"
resolved "https://registry.yarnpkg.com/@dcloudio/uni-i18n/-/uni-i18n-2.0.0-31920210514002.tgz#f63d14c234ea0353fabe2d8c681601c7ba07e488"
integrity sha512-shHf27U0KEs//ieCBG1R1aRKNDn6KwcVUIb5GsPuDOqoN7WQY+nEz9QFdOSQY8j9tX4ABOAc1ra0Opz8xFVngA==
"@hapi/address@2.x.x":
version "2.1.4"
......@@ -993,7 +992,6 @@
"@rollup/plugin-json@^4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-4.1.0.tgz#54e09867ae6963c593844d8bd7a9c718294496f3"
integrity sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==
dependencies:
"@rollup/pluginutils" "^3.0.8"
......@@ -4642,6 +4640,17 @@ human-signals@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
i18n@^0.13.3:
version "0.13.3"
resolved "https://registry.yarnpkg.com/i18n/-/i18n-0.13.3.tgz#5820f48d87a77cf14e064719bee9bc682ed550eb"
dependencies:
debug "^4.1.1"
make-plural "^6.2.2"
math-interval-parser "^2.0.1"
messageformat "^2.3.0"
mustache "^4.0.1"
sprintf-js "^1.1.2"
iconv-lite@0.4.24, iconv-lite@^0.4.24:
version "0.4.24"
resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
......@@ -5920,6 +5929,16 @@ make-dir@^3.0.0, make-dir@^3.0.2:
dependencies:
semver "^6.0.0"
make-plural@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-4.3.0.tgz#f23de08efdb0cac2e0c9ba9f315b0dff6b4c2735"
optionalDependencies:
minimist "^1.2.0"
make-plural@^6.2.2:
version "6.2.2"
resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-6.2.2.tgz#beb5fd751355e72660eeb2218bb98eec92853c6c"
makeerror@1.0.x:
version "1.0.11"
resolved "https://registry.npmjs.org/makeerror/-/makeerror-1.0.11.tgz#e01a5c9109f2af79660e4e8b9587790184f5a96c"
......@@ -5956,6 +5975,10 @@ matched@^0.4.1:
lazy-cache "^2.0.1"
resolve-dir "^0.1.0"
math-interval-parser@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/math-interval-parser/-/math-interval-parser-2.0.1.tgz#e22cd6d15a0a7f4c03aec560db76513da615bed4"
md5.js@^1.3.4:
version "1.3.5"
resolved "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"
......@@ -6016,6 +6039,22 @@ merge2@^1.2.3, merge2@^1.3.0:
version "1.3.0"
resolved "https://registry.npmjs.org/merge2/-/merge2-1.3.0.tgz#5b366ee83b2f1582c48f87e47cf1a9352103ca81"
messageformat-formatters@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/messageformat-formatters/-/messageformat-formatters-2.0.1.tgz#0492c1402a48775f751c9b17c0354e92be012b08"
messageformat-parser@^4.1.2:
version "4.1.3"
resolved "https://registry.yarnpkg.com/messageformat-parser/-/messageformat-parser-4.1.3.tgz#b824787f57fcda7d50769f5b63e8d4fda68f5b9e"
messageformat@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/messageformat/-/messageformat-2.3.0.tgz#de263c49029d5eae65d7ee25e0754f57f425ad91"
dependencies:
make-plural "^4.3.0"
messageformat-formatters "^2.0.1"
messageformat-parser "^4.1.2"
methods@~1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
......@@ -6251,6 +6290,10 @@ multicast-dns@^6.0.1:
dns-packet "^1.3.1"
thunky "^1.0.2"
mustache@^4.0.1:
version "4.2.0"
resolved "https://registry.yarnpkg.com/mustache/-/mustache-4.2.0.tgz#e5892324d60a12ec9c2a73359edca52972bf6f64"
mustache@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/mustache/-/mustache-4.1.0.tgz#8c1b042238a982d2eb2d30efc6c14296ae3f699d"
......@@ -8210,6 +8253,10 @@ split-string@^3.0.1, split-string@^3.0.2:
dependencies:
extend-shallow "^3.0.0"
sprintf-js@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.2.tgz#da1765262bf8c0f571749f2ad6c26300207ae673"
sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册