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",
"docs:build": " dumi build",
"docs:dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider dumi dev ",
"autopub": "autopub",
"autopub:all": "autopub --all"
"publish:auto": "autopub --all",
"publish:all": "autopub"
},
"author": "",
"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,38 +1,46 @@
{
"name": "react-cra-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"name": "i18napp",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@voerkai18n/runtime": "^1.1.18",
"@voerkai18n/utils": "workspace:^1.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"voerkai18n-loader": "workspace:^1.0.0",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox 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
</a>
<div>
t("中国")<br/>
t("中华人民共和国")<br/>
t('中国')<br/>
t('中华人民共和国')<br/>
t("中国",1)<br/>
t("中华人民共和国","fdf")<br/>
</div>
</header>
</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

@ -107,12 +107,20 @@ function readIdMapFile(options){
searchIdMapFiles.push(pathobj.join(location,"src","languages/idMap.js"))
searchIdMapFiles.push(pathobj.join(location,"languages/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)
searchIdMapFiles.push(pathobj.join(projectRoot,"src","languages/idMap.js"))
searchIdMapFiles.push(pathobj.join(projectRoot,"languages/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
for( idMapFile of searchIdMapFiles){
// 如果不存在idMap文件则尝试从location/languages/中导入

View File

@ -1,12 +1,12 @@
{
"name": "@voerkai18n/babel",
"version": "1.0.32",
"version": "1.0.33",
"description": "Babel插件实现自动导入t函数和自动文本映射",
"main": "index.js",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": {
"type": "git",
"url": "git+https://gitee.com/zhangfisher/voerka-i18n.git"
"url": "git+https://github.com/zhangfisher/voerka-i18n"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
@ -17,5 +17,5 @@
"dependencies": {
"@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",
"version": "1.0.46",
"version": "1.0.47",
"description": "命令行工具,用来初始化/提取/编译/自动翻译等工具链",
"main": "index.js",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": {
"type": "git",
"url": "git+https://gitee.com/zhangfisher/voerka-i18n.git"
"url": "git+https://github.com/zhangfisher/voerka-i18n"
},
"keywords": [
"i18n",
@ -47,5 +47,5 @@
"through2": "^4.0.2",
"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",
"version": "1.0.15",
"version": "1.0.16",
"description": "格式化器,提供对要翻译文本的转换功能",
"main": "index.js",
"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"
},
@ -15,5 +20,5 @@
"dependencies": {
"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",
"version": "1.0.11",
"version": "1.0.12",
"description": "React支持,提供语言切换等功能",
"main": "index.jsx",
"typings": "index.d.ts",
"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",
"release": "pnpm autopublish"
@ -17,5 +22,5 @@
"peerDependencies": {
"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",
"version": "1.1.18",
"version": "1.1.19",
"description": "核心运行时",
"main": "./dist/index.cjs",
"module": "./dist/index.esm.js",
@ -8,7 +8,7 @@
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": {
"type": "git",
"url": "git+https://gitee.com/zhangfisher/voerka-i18n.git"
"url": "git+https://github.com/zhangfisher/voerka-i18n"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
@ -40,5 +40,5 @@
"rollup-plugin-clear": "^2.0.7",
"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配置为默认回退语言
*/
_initiLanguages(){
if(!isPlainObject(this._languages)){
if(!Array.isArray(this._languages)){
console.warn("[VoerkaI18n] 无效的语言配置")
this._languages = [
{

View File

@ -1,6 +1,6 @@
{
"name": "@voerkai18n/utils",
"version": "1.0.21",
"version": "1.0.22",
"description": "公共工具库",
"main": "index.js",
"scripts": {
@ -13,5 +13,5 @@
"fs-extra": "^10.0.1",
"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",
"version": "1.0.21",
"version": "1.0.22",
"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",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
@ -13,7 +17,7 @@
"dependencies": {
"@voerkai18n/utils": "workspace:latest"
},
"lastPublish": "2023-01-26T21:27:37+08:00",
"lastPublish": "2023-01-27T20:55:25+08:00",
"devDependencies": {
"vite": "^4.0.4"
}

View File

@ -1,9 +1,14 @@
{
"name": "@voerkai18n/vue",
"version": "1.0.14",
"version": "1.0.15",
"description": "Vue3插件,提供自动插件翻译函数和语言切换功能",
"main": "index.js",
"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",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
@ -14,5 +19,5 @@
"@voerkai18n/runtime": "workspace:^1.1.16",
"vue": "latest"
},
"lastPublish": "2023-01-26T21:27:46+08:00"
"lastPublish": "2023-01-27T20:55:37+08:00"
}

View File

@ -1,18 +1,23 @@
{
"name": "voerkai18n-loader",
"version": "1.0.0",
"description": "voerkai18n loader for webpack",
"main": "loader.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"loader-runner": "^4.3.0"
},
"dependencies": {
"@voerkai18n/utils": "workspace:^1.0.21"
}
}
"name": "voerkai18n-loader",
"version": "1.0.2",
"description": "voerkai18n loader for webpack",
"main": "loader.js",
"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"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"loader-runner": "^4.3.0"
},
"dependencies": {
"@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