update react-cra-app

This commit is contained in:
wxzhang 2023-01-27 21:03:37 +08:00
parent a626ff122f
commit d1d9f503cd
21 changed files with 5729 additions and 502 deletions

View File

@ -9,8 +9,8 @@
"test:runtime": "cross-env NODE_OPTIONS=--experimental-vm-modules jest runtime --coverage --collectCoverageFrom packages/runtime/dist/runtime.cjs", "test:runtime": "cross-env NODE_OPTIONS=--experimental-vm-modules jest runtime --coverage --collectCoverageFrom packages/runtime/dist/runtime.cjs",
"docs:build": " dumi build", "docs:build": " dumi build",
"docs:dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider dumi dev ", "docs:dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider dumi dev ",
"autopub": "autopub", "publish:auto": "autopub --all",
"autopub:all": "autopub --all" "publish:all": "autopub"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",

33
packages/apps/react-cra-app/App.js vendored Normal file
View File

@ -0,0 +1,33 @@
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
<div>
t("中国")<br/>
t("中华人民共和国")<br/>
t('中国')<br/>
t('中华人民共和国')<br/>
t("中国",1)<br/>
t("中华人民共和国","fdf")<br/>
</div>
</header>
</div>
);
}
export default App;

View File

@ -0,0 +1,40 @@
const path = require("path");
module.exports = {
webpack: {
configure:(config, { env, paths })=>{
// console.log(JSON.stringify(config.module.rules,null,4))
config.module.rules.push(
{
test: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/],
use:[
{
loader:"voerkai18n-loader",
options: {
autoImport:true,
debug:true
}
}
],
include: paths.appSrc,
enforce:'pre',
}
)
return config
}
// configure: {
// module: {
// rules: [
// {
// //test: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/],
// loader: "voerkai18n-loader",
// enforce: "pre",
// options: {
// a: 1,
// },
// },
// ],
// },
// },
},
};

View File

@ -1,20 +1,23 @@
{ {
"name": "react-cra-app", "name": "i18napp",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@testing-library/jest-dom": "^5.16.5", "@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"@voerkai18n/runtime": "^1.1.18",
"@voerkai18n/utils": "workspace:^1.0.0",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"voerkai18n-loader": "workspace:^1.0.0",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "craco start",
"build": "react-scripts build", "build": "craco build",
"test": "react-scripts test", "test": "craco test",
"eject": "react-scripts eject" "eject": "react-scripts eject"
}, },
"eslintConfig": { "eslintConfig": {
@ -34,5 +37,10 @@
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
},
"devDependencies": {
"@craco/craco": "^7.0.0",
"loader-utils": "^3.2.1"
} }
} }

View File

@ -17,6 +17,14 @@ function App() {
> >
Learn React Learn React
</a> </a>
<div>
t("中国")<br/>
t("中华人民共和国")<br/>
t('中国')<br/>
t('中华人民共和国')<br/>
t("中国",1)<br/>
t("中华人民共和国","fdf")<br/>
</div>
</header> </header>
</div> </div>
); );

View File

@ -0,0 +1,4 @@
module.exports = {
中国:1,
中华人民共和国:2
}

View File

@ -0,0 +1,42 @@
/**
* 初始化入口
*
* 本文件仅供在执行voerkai18n extract&compile前提供t函数引用
*
*/
import runtime from "@voerkai18n/runtime"
const { translate,VoerkaI18nScope } = runtime
// 语言作用域
const scope = new VoerkaI18nScope({
id : "", // 当前作用域的id自动取当前工程的package.json的name
debug : false, // 是否在控制台输出高度信息
default : {}, // 默认语言包
messages : {}, // 当前语言包
idMap : {}, // 消息id映射列表
formatters : {}, // 扩展自定义格式化器
loaders : {}, // 语言包加载器
defaultLanguage: 'zh', // 默认语言名称
activeLanguage: 'zh', // 当前语言名称
languages: [
{
name: "zh",
title: "中文"
},
{
name: "en",
title: "英文"
}
]
})
// 翻译函数
const scopedTtranslate = translate.bind(scope)
export {
scopedTtranslate as t,
scope as i18nScope
}

View File

@ -0,0 +1,15 @@
{
"languages": [
{
"name": "zh",
"title": "中文"
},
{
"name": "en",
"title": "英语"
}
],
"defaultLanguage": "zh",
"activeLanguage": "zh",
"namespaces": {}
}

View File

@ -108,11 +108,19 @@ function readIdMapFile(options){
searchIdMapFiles.push(pathobj.join(location,"languages/idMap.js")) searchIdMapFiles.push(pathobj.join(location,"languages/idMap.js"))
searchIdMapFiles.push(pathobj.join(location,"idMap.js")) searchIdMapFiles.push(pathobj.join(location,"idMap.js"))
searchIdMapFiles.push(pathobj.join(location,"src","languages/idMap.ts"))
searchIdMapFiles.push(pathobj.join(location,"languages/idMap.ts"))
searchIdMapFiles.push(pathobj.join(location,"idMap.ts"))
let projectRoot = getProjectRootFolder(location) let projectRoot = getProjectRootFolder(location)
searchIdMapFiles.push(pathobj.join(projectRoot,"src","languages/idMap.js")) searchIdMapFiles.push(pathobj.join(projectRoot,"src","languages/idMap.js"))
searchIdMapFiles.push(pathobj.join(projectRoot,"languages/idMap.js")) searchIdMapFiles.push(pathobj.join(projectRoot,"languages/idMap.js"))
searchIdMapFiles.push(pathobj.join(projectRoot,"idMap.js")) searchIdMapFiles.push(pathobj.join(projectRoot,"idMap.js"))
searchIdMapFiles.push(pathobj.join(projectRoot,"src","languages/idMap.ts"))
searchIdMapFiles.push(pathobj.join(projectRoot,"languages/idMap.ts"))
searchIdMapFiles.push(pathobj.join(projectRoot,"idMap.ts"))
let idMapFile let idMapFile
for( idMapFile of searchIdMapFiles){ for( idMapFile of searchIdMapFiles){
// 如果不存在idMap文件则尝试从location/languages/中导入 // 如果不存在idMap文件则尝试从location/languages/中导入

View File

@ -1,12 +1,12 @@
{ {
"name": "@voerkai18n/babel", "name": "@voerkai18n/babel",
"version": "1.0.32", "version": "1.0.33",
"description": "Babel插件实现自动导入t函数和自动文本映射", "description": "Babel插件实现自动导入t函数和自动文本映射",
"main": "index.js", "main": "index.js",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n", "homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://gitee.com/zhangfisher/voerka-i18n.git" "url": "git+https://github.com/zhangfisher/voerka-i18n"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
@ -17,5 +17,5 @@
"dependencies": { "dependencies": {
"@voerkai18n/utils": "workspace:latest" "@voerkai18n/utils": "workspace:latest"
}, },
"lastPublish": "2023-01-26T21:27:24+08:00" "lastPublish": "2023-01-27T20:55:13+08:00"
} }

View File

@ -1,12 +1,12 @@
{ {
"name": "@voerkai18n/cli", "name": "@voerkai18n/cli",
"version": "1.0.46", "version": "1.0.47",
"description": "命令行工具,用来初始化/提取/编译/自动翻译等工具链", "description": "命令行工具,用来初始化/提取/编译/自动翻译等工具链",
"main": "index.js", "main": "index.js",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n", "homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://gitee.com/zhangfisher/voerka-i18n.git" "url": "git+https://github.com/zhangfisher/voerka-i18n"
}, },
"keywords": [ "keywords": [
"i18n", "i18n",
@ -47,5 +47,5 @@
"through2": "^4.0.2", "through2": "^4.0.2",
"vinyl": "^2.2.1" "vinyl": "^2.2.1"
}, },
"lastPublish": "2023-01-26T21:27:14+08:00" "lastPublish": "2023-01-27T20:55:01+08:00"
} }

View File

@ -1,8 +1,13 @@
{ {
"name": "@voerkai18n/formatters", "name": "@voerkai18n/formatters",
"version": "1.0.15", "version": "1.0.16",
"description": "格式化器,提供对要翻译文本的转换功能", "description": "格式化器,提供对要翻译文本的转换功能",
"main": "index.js", "main": "index.js",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": {
"type": "git",
"url": "git+https://github.com/zhangfisher/voerka-i18n"
},
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
@ -15,5 +20,5 @@
"dependencies": { "dependencies": {
"dayjs": "^1.11.0" "dayjs": "^1.11.0"
}, },
"lastPublish": "2023-01-26T21:26:47+08:00" "lastPublish": "2023-01-27T20:54:24+08:00"
} }

View File

@ -1,9 +1,14 @@
{ {
"name": "@voerkai18n/react", "name": "@voerkai18n/react",
"version": "1.0.11", "version": "1.0.12",
"description": "React支持,提供语言切换等功能", "description": "React支持,提供语言切换等功能",
"main": "index.jsx", "main": "index.jsx",
"typings": "index.d.ts", "typings": "index.d.ts",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": {
"type": "git",
"url": "git+https://github.com/zhangfisher/voerka-i18n"
},
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"release": "pnpm autopublish" "release": "pnpm autopublish"
@ -17,5 +22,5 @@
"peerDependencies": { "peerDependencies": {
"react": "^17.0.2" "react": "^17.0.2"
}, },
"lastPublish": "2023-01-26T21:26:56+08:00" "lastPublish": "2023-01-27T20:54:45+08:00"
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@voerkai18n/runtime", "name": "@voerkai18n/runtime",
"version": "1.1.18", "version": "1.1.19",
"description": "核心运行时", "description": "核心运行时",
"main": "./dist/index.cjs", "main": "./dist/index.cjs",
"module": "./dist/index.esm.js", "module": "./dist/index.esm.js",
@ -8,7 +8,7 @@
"homepage": "https://gitee.com/zhangfisher/voerka-i18n", "homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://gitee.com/zhangfisher/voerka-i18n.git" "url": "git+https://github.com/zhangfisher/voerka-i18n"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
@ -40,5 +40,5 @@
"rollup-plugin-clear": "^2.0.7", "rollup-plugin-clear": "^2.0.7",
"rollup-plugin-terser": "^7.0.2" "rollup-plugin-terser": "^7.0.2"
}, },
"lastPublish": "2023-01-26T21:26:37+08:00" "lastPublish": "2023-01-27T20:54:12+08:00"
} }

View File

@ -60,7 +60,7 @@ module.exports = class VoerkaI18nScope {
* - 将en配置为默认回退语言 * - 将en配置为默认回退语言
*/ */
_initiLanguages(){ _initiLanguages(){
if(!isPlainObject(this._languages)){ if(!Array.isArray(this._languages)){
console.warn("[VoerkaI18n] 无效的语言配置") console.warn("[VoerkaI18n] 无效的语言配置")
this._languages = [ this._languages = [
{ {

View File

@ -1,6 +1,6 @@
{ {
"name": "@voerkai18n/utils", "name": "@voerkai18n/utils",
"version": "1.0.21", "version": "1.0.22",
"description": "公共工具库", "description": "公共工具库",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
@ -13,5 +13,5 @@
"fs-extra": "^10.0.1", "fs-extra": "^10.0.1",
"shelljs": "^0.8.5" "shelljs": "^0.8.5"
}, },
"lastPublish": "2023-01-26T21:26:23+08:00" "lastPublish": "2023-01-27T20:53:53+08:00"
} }

View File

@ -1,8 +1,12 @@
{ {
"name": "@voerkai18n/vite", "name": "@voerkai18n/vite",
"version": "1.0.21", "version": "1.0.22",
"description": "Vite插件,提供自动插入翻译函数和文本映射等功能", "description": "Vite插件,提供自动插入翻译函数和文本映射等功能",
"main": "index.js", "homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": {
"type": "git",
"url": "git+https://github.com/zhangfisher/voerka-i18n"
}, "main": "index.js",
"types": "index.d.ts", "types": "index.d.ts",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
@ -13,7 +17,7 @@
"dependencies": { "dependencies": {
"@voerkai18n/utils": "workspace:latest" "@voerkai18n/utils": "workspace:latest"
}, },
"lastPublish": "2023-01-26T21:27:37+08:00", "lastPublish": "2023-01-27T20:55:25+08:00",
"devDependencies": { "devDependencies": {
"vite": "^4.0.4" "vite": "^4.0.4"
} }

View File

@ -1,9 +1,14 @@
{ {
"name": "@voerkai18n/vue", "name": "@voerkai18n/vue",
"version": "1.0.14", "version": "1.0.15",
"description": "Vue3插件,提供自动插件翻译函数和语言切换功能", "description": "Vue3插件,提供自动插件翻译函数和语言切换功能",
"main": "index.js", "main": "index.js",
"typings": "index.d.ts", "typings": "index.d.ts",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": {
"type": "git",
"url": "git+https://github.com/zhangfisher/voerka-i18n"
},
"types": "index.d.ts", "types": "index.d.ts",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
@ -14,5 +19,5 @@
"@voerkai18n/runtime": "workspace:^1.1.16", "@voerkai18n/runtime": "workspace:^1.1.16",
"vue": "latest" "vue": "latest"
}, },
"lastPublish": "2023-01-26T21:27:46+08:00" "lastPublish": "2023-01-27T20:55:37+08:00"
} }

View File

@ -1,9 +1,13 @@
{ {
"name": "voerkai18n-loader", "name": "voerkai18n-loader",
"version": "1.0.0", "version": "1.0.2",
"description": "voerkai18n loader for webpack", "description": "voerkai18n loader for webpack",
"main": "loader.js", "main": "loader.js",
"scripts": { "homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": {
"type": "git",
"url": "git+https://github.com/zhangfisher/voerka-i18n"
}, "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"keywords": [], "keywords": [],
@ -14,5 +18,6 @@
}, },
"dependencies": { "dependencies": {
"@voerkai18n/utils": "workspace:^1.0.21" "@voerkai18n/utils": "workspace:^1.0.21"
} },
"lastPublish": "2023-01-27T20:55:54+08:00"
} }

View File

@ -0,0 +1,6 @@
[![fisher/voerka-i18n](https://gitee.com/zhangfisher/voerka-i18n/widgets/widget_card.svg?colors=4183c4,ffffff,ffffff,e3e9ed,666666,9b9b9b)](https://gitee.com/zhangfisher/voerka-i18n)
源码与文档:[https://gitee.com/zhangfisher/voerka-i18n](https://zhangfisher.github.io/voerka-i18n/)

5887
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff