update runtime

This commit is contained in:
wxzhang 2022-08-07 21:11:19 +08:00
parent 154e015fa5
commit 6d2ba85204
19 changed files with 126 additions and 172 deletions

2
.gitignore vendored
View File

@ -13,3 +13,5 @@ node_modules/
.umi .umi
.umi-production .umi-production
/docs/dist /docs/dist
dist
/packages/runtime/dist

View File

@ -1,51 +0,0 @@
version: '1.0'
name: branch-pipeline
displayName: BranchPipeline
stages:
- stage:
name: compile
displayName: 编译
steps:
- step: build@nodejs
name: build_nodejs
displayName: Nodejs 构建
# 支持8.16.2、10.17.0、12.16.1、14.16.0、15.12.0五个版本
nodeVersion: 14.16.0
# 构建命令:安装依赖 -> 清除上次打包产物残留 -> 执行构建 【请根据项目实际产出进行填写】
commands:
- npm install && rm -rf ./dist && npm run build
# 非必填字段开启后表示将构建产物暂存但不会上传到制品库中7天后自动清除
artifacts:
# 构建产物名字作为产物的唯一标识可向下传递支持自定义默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
- name: BUILD_ARTIFACT
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
path:
- ./dist
- step: publish@general_artifacts
name: publish_general_artifacts
displayName: 上传制品
# 上游构建任务定义的产物名默认BUILD_ARTIFACT
dependArtifact: BUILD_ARTIFACT
# 上传到制品库时的制品命名默认output
artifactName: output
dependsOn: build_nodejs
- stage:
name: release
displayName: 发布
steps:
- step: publish@release_artifacts
name: publish_release_artifacts
displayName: '发布'
# 上游上传制品任务的产出
dependArtifact: output
# 发布制品版本号
version: '1.0.0.0'
# 是否开启版本号自增,默认开启
autoIncrement: true
triggers:
push:
branches:
exclude:
- master
include:
- .*

View File

@ -1,49 +0,0 @@
version: '1.0'
name: master-pipeline
displayName: MasterPipeline
stages:
- stage:
name: compile
displayName: 编译
steps:
- step: build@nodejs
name: build_nodejs
displayName: Nodejs 构建
# 支持8.16.2、10.17.0、12.16.1、14.16.0、15.12.0五个版本
nodeVersion: 14.16.0
# 构建命令:安装依赖 -> 清除上次打包产物残留 -> 执行构建 【请根据项目实际产出进行填写】
commands:
- npm install && rm -rf ./dist && npm run build
# 非必填字段开启后表示将构建产物暂存但不会上传到制品库中7天后自动清除
artifacts:
# 构建产物名字作为产物的唯一标识可向下传递支持自定义默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
- name: BUILD_ARTIFACT
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
path:
- ./dist
- step: publish@general_artifacts
name: publish_general_artifacts
displayName: 上传制品
# 上游构建任务定义的产物名默认BUILD_ARTIFACT
dependArtifact: BUILD_ARTIFACT
# 上传到制品库时的制品命名默认output
artifactName: output
dependsOn: build_nodejs
- stage:
name: release
displayName: 发布
steps:
- step: publish@release_artifacts
name: publish_release_artifacts
displayName: '发布'
# 上游上传制品任务的产出
dependArtifact: output
# 发布制品版本号
version: '1.0.0.0'
# 是否开启版本号自增,默认开启
autoIncrement: true
triggers:
push:
branches:
include:
- master

View File

@ -1,36 +0,0 @@
version: '1.0'
name: pr-pipeline
displayName: PRPipeline
stages:
- stage:
name: compile
displayName: 编译
steps:
- step: build@nodejs
name: build_nodejs
displayName: Nodejs 构建
# 支持8.16.2、10.17.0、12.16.1、14.16.0、15.12.0五个版本
nodeVersion: 14.16.0
# 构建命令:安装依赖 -> 清除上次打包产物残留 -> 执行构建 【请根据项目实际产出进行填写】
commands:
- npm install && rm -rf ./dist && npm run build
# 非必填字段开启后表示将构建产物暂存但不会上传到制品库中7天后自动清除
artifacts:
# 构建产物名字作为产物的唯一标识可向下传递支持自定义默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
- name: BUILD_ARTIFACT
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
path:
- ./dist
- step: publish@general_artifacts
name: publish_general_artifacts
displayName: 上传制品
# 上游构建任务定义的产物名默认BUILD_ARTIFACT
dependArtifact: BUILD_ARTIFACT
# 上传到制品库时的制品命名默认output
artifactName: output
dependsOn: build_nodejs
triggers:
pr:
branches:
include:
- master

View File

@ -1,11 +1,11 @@
# 版本信息 # 版本信息
| 包| 版本号| 最后更新|说明| | 包| 版本号| 最后更新|说明|
| --- | :---:| --- |---| | --- | :---:| --- |---|
|**@voerkai18n/utils**|1.0.12|08/05|公共工具库 |**@voerkai18n/utils**|1.0.12|2022/08/05|公共工具库
|**@voerkai18n/runtime**|1.0.27|08/05|核心运行时 |**@voerkai18n/runtime**|1.0.28|2022/08/07|核心运行时
|**@voerkai18n/formatters**|1.0.6|04/15|格式化器,提供对要翻译文本的转换功能 |**@voerkai18n/formatters**|1.0.6|2022/04/15|格式化器,提供对要翻译文本的转换功能
|**@voerkai18n/react**|1.0.4|04/16|React支持,提供语言切换等功能 |**@voerkai18n/react**|1.0.4|2022/04/16|React支持,提供语言切换等功能
|**@voerkai18n/cli**|1.0.32|08/05|命令行工具,用来初始化/提取/编译/自动翻译等工具链 |**@voerkai18n/cli**|1.0.33|2022/08/07|命令行工具,用来初始化/提取/编译/自动翻译等工具链
|**@voerkai18n/babel**|1.0.23|08/05|Babel插件实现自动导入t函数和自动文本映射 |**@voerkai18n/babel**|1.0.23|2022/08/05|Babel插件实现自动导入t函数和自动文本映射
|**@voerkai18n/vite**|1.0.12|08/05|Vite插件,提供自动插入翻译函数和文本映射等功能 |**@voerkai18n/vite**|1.0.12|2022/08/05|Vite插件,提供自动插入翻译函数和文本映射等功能
|**@voerkai18n/vue**|1.0.5|04/15|Vue3插件,提供自动插件翻译函数和语言切换功能 |**@voerkai18n/vue**|1.0.5|2022/04/15|Vue3插件,提供自动插件翻译函数和语言切换功能

View File

@ -4,7 +4,6 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build:runtime": "pnpm build --filter \"@voerkai18n/runtime\"",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules node node_modules/jest/bin/jest.js ", "test": "cross-env NODE_OPTIONS=--experimental-vm-modules node node_modules/jest/bin/jest.js ",
"test:app": "cross-env NODE_OPTIONS=--experimental-vm-modules node node_modules/jest/bin/jest.js -- app", "test:app": "cross-env NODE_OPTIONS=--experimental-vm-modules node node_modules/jest/bin/jest.js -- app",
"list:package": "node ./packages/autopublish/index.js list", "list:package": "node ./packages/autopublish/index.js list",

View File

@ -1,7 +1,14 @@
const i18nPlugin =require("@voerkai18n/babel") const i18nPlugin =require("@voerkai18n/babel")
module.exports = { module.exports = {
presets: [ presets: [
"@babel/preset-env" "@babel/preset-env",
{
corejs: {
useBuiltIns: 'entry',
version: "3.8",
proposals: true
}
}
], ],
plugins: [ plugins: [
[ [

View File

@ -1,4 +1,4 @@
{ {
"3": "全世界迎接中华民族的伟大复兴!" "3": "全世界迎接中华民族的伟大复兴!"
} }

View File

@ -4,6 +4,7 @@ import {reactive } from 'vue'
// This starter template is using Vue 3 <script setup> SFCs // This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup // Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import China from './components/china.vue' import China from './components/china.vue'
import Formatters from './components/formatters.vue'
let messages = reactive({ let messages = reactive({
name: t('VoerkaI18n多语言解决方案 ') name: t('VoerkaI18n多语言解决方案 ')
@ -39,15 +40,18 @@ export default {
} }
</script> </script>
<template> <template>
<img alt="Vue logo" src="./assets/logo.png" /> <div>
<h1>{{ t("中华人民共和国")}} </h1> <img alt="Vue logo" src="./assets/logo.png" />
<h2>{{ t("迎接中华民族的伟大复兴")}} </h2> <h1>{{ t("中华人民共和国")}} </h1>
<China :title="t('中华人民共和国')" /> <h2>{{ t("迎接中华民族的伟大复兴")}} </h2>
<h5>默认语言{{ i18n.defaultLanguage }}</h5> <China :title="t('中华人民共和国')" />
<h5>当前语言{{ i18n.activeLanguage.value }}</h5> <Formatters/>
<button v-for="lng of i18n.languages" @click="i18n.activeLanguage = lng.name" style="padding:8px;margin:8px;cursor:pointer" :style="{'outline' : lng.name === i18n.activeLanguage.value ? '2px red solid' : ''}" >{{ lng.title }}</button> <h5>默认语言{{ i18n.defaultLanguage }}</h5>
<button @click="i18n.activeLanguage = 'de'" style="padding:8px;margin:8px;cursor:pointer" :style="{'outline' : i18n.activeLanguage.value === 'de' ? '2px red solid' : ''}" >德语</button> <h5>当前语言{{ i18n.activeLanguage.value }}</h5>
<button @click="i18n.activeLanguage = 'jp'" style="padding:8px;margin:8px;cursor:pointer" :style="{'outline' : i18n.activeLanguage.value === 'jp' ? '2px red solid' : ''}" >日语</button> <button :key="lng.name" v-for="lng of i18n.languages" @click="i18n.activeLanguage = lng.name" style="padding:8px;margin:8px;cursor:pointer" :style="{'outline' : lng.name === i18n.activeLanguage.value ? '2px red solid' : ''}" >{{ lng.title }}</button>
<button @click="i18n.activeLanguage = 'de'" style="padding:8px;margin:8px;cursor:pointer" :style="{'outline' : i18n.activeLanguage.value === 'de' ? '2px red solid' : ''}" >德语</button>
<button @click="i18n.activeLanguage = 'jp'" style="padding:8px;margin:8px;cursor:pointer" :style="{'outline' : i18n.activeLanguage.value === 'jp' ? '2px red solid' : ''}" >日语</button>
</div>
</template> </template>

View File

@ -0,0 +1,33 @@
<script setup>
defineProps({
title: String
})
</script>
<script>
export default {
data() {
return {
date1: new Date(),
date2: "2022/12/3 19:08:12",
date3: 1659872118897,
}
}
}
</script>
<template>
<div style="padding:16px;border:1px red solid;line-height:120%;margin:0 auto;margin-bottom:16px;width:600px;">
<p>{{ t("现在是{ value | date }",date1)}} </p>
<p>{{ t("现在是{ value | date }",date2)}} </p>
<p>{{ t("现在是{ value | date }",date3)}} </p>
</div>
</template>
<style scoped>
a {
color: #42b983;
}
</style>

View File

@ -59,7 +59,7 @@ export default{
$types:{ $types:{
}, },
cn:{ zh:{
$types:{ $types:{
// 所有类型的默认格式化器 // 所有类型的默认格式化器
// "*":{ // "*":{

View File

@ -366,7 +366,8 @@ function generatePackageVersionDoc(){
const lastPublish = package.lastPublish ? dayjs(package.lastPublish).format("YYYY/MM/DD") : "None" const lastPublish = package.lastPublish ? dayjs(package.lastPublish).format("YYYY/MM/DD") : "None"
results.push(`|**${package.name}**|${package.version}|${lastPublish}|${package.description}`) results.push(`|**${package.name}**|${package.version}|${lastPublish}|${package.description}`)
}) })
fs.writeFileSync(path.join(workspaceRoot,"docs/zh/guide/intro/versions.md"), results.join("\n"))
fs.writeFileSync(path.join(workspaceRoot,"docs/src/guide/intro/versions.md"), results.join("\n"))
} }
async function answerForSelectPackages(packages,options){ async function answerForSelectPackages(packages,options){

View File

@ -157,7 +157,7 @@ var scope = class i18nScope {
} }
this.global = globalThis.VoerkaI18n; this.global = globalThis.VoerkaI18n;
this._mergePatchedMessages(); this._mergePatchedMessages();
this._patch(this._messages,newLanguage); this._patch(this._messages,this.activeLanguage);
// 正在加载语言包标识 // 正在加载语言包标识
this._loading=false; this._loading=false;
// 在全局注册作用域 // 在全局注册作用域
@ -362,20 +362,28 @@ var formatters = {
$types:{ $types:{
Date:(value)=>value.toLocaleString() Date:(value)=>value.toLocaleString()
}, },
// 日期
date: (value)=> value.toLocaleDateString(),
shortdate: (value)=> `${value.getFullYear()}-${value.getMonth()+1}-${value.getDate()}`,
// 时间
time:(value)=> value.toLocaleTimeString(), time:(value)=> value.toLocaleTimeString(),
shorttime:(value)=> value.toLocaleTimeString(), shorttime:(value)=> value.toLocaleTimeString(),
date: (value)=> value.toLocaleDateString(),
dict, //字典格式化器 dict, //字典格式化器
}, },
zh:{ zh:{
$types:{ $types:{
Date:(value)=> `${value.getFullYear()}${value.getMonth()+1}${value.getDate()}${value.getHours()}${value.getMinutes()}${value.getSeconds()}` Date:(value)=> `${value.getFullYear()}${value.getMonth()+1}${value.getDate()}${value.getHours()}${value.getMinutes()}${value.getSeconds()}`
}, },
shortime:(value)=> value.toLocaleTimeString(), // 日期
time:(value)=>`${value.getHours()}${value.getMinutes()}${value.getSeconds()}`,
date: (value)=> `${value.getFullYear()}${value.getMonth()+1}${value.getDate()}`, date: (value)=> `${value.getFullYear()}${value.getMonth()+1}${value.getDate()}`,
shortdate: (value)=> `${value.getFullYear()}-${value.getMonth()+1}-${value.getDate()}`, shortdate: (value)=> `${value.getFullYear()}-${value.getMonth()+1}-${value.getDate()}`,
currency:(value)=>`${value}`, // 时间
shortime:(value)=> value.toLocaleTimeString(),
time:(value)=>`${value.getHours()}${value.getMinutes()}${value.getSeconds()}`,
// 货币
currency:(value)=>`${value}`,
}, },
en:{ en:{
currency:(value)=>{ currency:(value)=>{

View File

@ -1,6 +1,6 @@
{ {
"name": "@voerkai18n/cli", "name": "@voerkai18n/cli",
"version": "1.0.32", "version": "1.0.33",
"description": "命令行工具,用来初始化/提取/编译/自动翻译等工具链", "description": "命令行工具,用来初始化/提取/编译/自动翻译等工具链",
"main": "index.js", "main": "index.js",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n", "homepage": "https://gitee.com/zhangfisher/voerka-i18n",
@ -50,5 +50,5 @@
"devDependencies": { "devDependencies": {
"@voerkai18n/autopublish": "workspace:^1.0.2" "@voerkai18n/autopublish": "workspace:^1.0.2"
}, },
"lastPublish": "2022-08-05T16:45:44+08:00" "lastPublish": "2022-08-07T19:16:38+08:00"
} }

View File

@ -45,20 +45,28 @@ module.exports = {
$types:{ $types:{
Date:(value)=>value.toLocaleString() Date:(value)=>value.toLocaleString()
}, },
// 日期
date: (value)=> value.toLocaleDateString(),
shortdate: (value)=> `${value.getFullYear()}-${value.getMonth()+1}-${value.getDate()}`,
// 时间
time:(value)=> value.toLocaleTimeString(), time:(value)=> value.toLocaleTimeString(),
shorttime:(value)=> value.toLocaleTimeString(), shorttime:(value)=> value.toLocaleTimeString(),
date: (value)=> value.toLocaleDateString(),
dict, //字典格式化器 dict, //字典格式化器
}, },
zh:{ zh:{
$types:{ $types:{
Date:(value)=> `${value.getFullYear()}${value.getMonth()+1}${value.getDate()}${value.getHours()}${value.getMinutes()}${value.getSeconds()}` Date:(value)=> `${value.getFullYear()}${value.getMonth()+1}${value.getDate()}${value.getHours()}${value.getMinutes()}${value.getSeconds()}`
}, },
shortime:(value)=> value.toLocaleTimeString(), // 日期
time:(value)=>`${value.getHours()}${value.getMinutes()}${value.getSeconds()}`,
date: (value)=> `${value.getFullYear()}${value.getMonth()+1}${value.getDate()}`, date: (value)=> `${value.getFullYear()}${value.getMonth()+1}${value.getDate()}`,
shortdate: (value)=> `${value.getFullYear()}-${value.getMonth()+1}-${value.getDate()}`, shortdate: (value)=> `${value.getFullYear()}-${value.getMonth()+1}-${value.getDate()}`,
currency:(value)=>`${value}`, // 时间
shortime:(value)=> value.toLocaleTimeString(),
time:(value)=>`${value.getHours()}${value.getMinutes()}${value.getSeconds()}`,
// 货币
currency:(value)=>`${value}`,
}, },
en:{ en:{
currency:(value)=>{ currency:(value)=>{

View File

@ -427,6 +427,26 @@ function getPluraMessage(messages,value){
return Array.isArray(messages) ? messages[0] : messages return Array.isArray(messages) ? messages[0] : messages
} }
} }
// if(!String.prototype.replaceAll){
// String.prototype.replaceAll = function(searchValue,replaceValue){
// if (!searchValue) return this
// if(typeof(searchValue)==="string"){
// return this.replace(new RegExp(searchValue,"gm"),replaceValue);
// }else if (searchValue instanceof RegExp) {
// const { global: globalFlag } = searchValue;
// if (!globalFlag) {
// throw new TypeError(
// '`String.prototype.replaceAll` ponyfill called with a non-global RegExp argument'
// );
// }
// return this.replace(searchValue, replaceValue);
// }
// }
// }
function escape(str){ function escape(str){
return str.replaceAll(/\\(?![trnbvf'"]{1})/g,"\\\\") return str.replaceAll(/\\(?![trnbvf'"]{1})/g,"\\\\")
.replaceAll("\t","\\t") .replaceAll("\t","\\t")

View File

@ -1,6 +1,6 @@
{ {
"name": "@voerkai18n/runtime", "name": "@voerkai18n/runtime",
"version": "1.0.27", "version": "1.0.28",
"description": "核心运行时", "description": "核心运行时",
"main": "./dist/index.cjs", "main": "./dist/index.cjs",
"module": "dist/index.esm.js", "module": "dist/index.esm.js",
@ -35,5 +35,5 @@
"rollup-plugin-terser": "^7.0.2", "rollup-plugin-terser": "^7.0.2",
"@voerkai18n/autopublish": "workspace:^1.0.2" "@voerkai18n/autopublish": "workspace:^1.0.2"
}, },
"lastPublish": "2022-08-05T16:36:41+08:00" "lastPublish": "2022-08-07T19:16:27+08:00"
} }

View File

@ -34,7 +34,7 @@ module.exports = class i18nScope {
} }
this.global = globalThis.VoerkaI18n this.global = globalThis.VoerkaI18n
this._mergePatchedMessages() this._mergePatchedMessages()
this._patch(this._messages,newLanguage) this._patch(this._messages,this.activeLanguage)
// 正在加载语言包标识 // 正在加载语言包标识
this._loading=false this._loading=false
// 在全局注册作用域 // 在全局注册作用域

8
pnpm-lock.yaml generated
View File

@ -19,6 +19,7 @@ importers:
inquirer: ^8.2.2 inquirer: ^8.2.2
jest: ^27.5.1 jest: ^27.5.1
logsets: ^1.0.8 logsets: ^1.0.8
pnpm: ^7.8.0
prettier: ^2.2.1 prettier: ^2.2.1
rollup: ^2.70.1 rollup: ^2.70.1
rollup-plugin-clear: ^2.0.7 rollup-plugin-clear: ^2.0.7
@ -42,6 +43,7 @@ importers:
gulp: 4.0.2 gulp: 4.0.2
jest: 27.5.1 jest: 27.5.1
logsets: 1.0.12 logsets: 1.0.12
pnpm: 7.9.0
prettier: 2.7.1 prettier: 2.7.1
rollup: 2.77.2 rollup: 2.77.2
rollup-plugin-clear: 2.0.7 rollup-plugin-clear: 2.0.7
@ -8858,6 +8860,12 @@ packages:
find-up: 4.1.0 find-up: 4.1.0
dev: true dev: true
/pnpm/7.9.0:
resolution: {integrity: sha512-xkIVw73yJm/h5M4VvFIS5Q+gQCRDrp3r92g58PtcCK86aZCa7EQ6q6ivdfTAz0KsAVgloA6Anub28n6wju5v3w==}
engines: {node: '>=14.6'}
hasBin: true
dev: true
/posix-character-classes/0.1.1: /posix-character-classes/0.1.1:
resolution: {integrity: sha512-xTgYBc3fuo7Yt7JbiuFxSYGToMoz8fLoE6TC9Wx1P/u+LfeThMOAqmuyECnlBaaJb+u1m9hHiXUEtwW4OzfUJg==} resolution: {integrity: sha512-xTgYBc3fuo7Yt7JbiuFxSYGToMoz8fLoE6TC9Wx1P/u+LfeThMOAqmuyECnlBaaJb+u1m9hHiXUEtwW4OzfUJg==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}