Skip to content

Commit

Permalink
Merge pull request #79 from zhangfisher/3.0
Browse files Browse the repository at this point in the history
3.0
  • Loading branch information
zhangfisher authored Jan 2, 2025
2 parents 9401033 + 460b072 commit dc60903
Show file tree
Hide file tree
Showing 81 changed files with 6,972 additions and 24,590 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/website.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ on:
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
# using the `master` branch as the default branch.
push:
branches: [master]
branches:
master

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
3 changes: 3 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@lite-tree/icons": "^1.0.6",
"@lite-tree/vue": "^1.1.4",
"flex-tools": "^1.4.11",
"flex-tools": "^1.4.12",
"flexstyled": "^2.1.2"
}
}
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"sync": "cnpm sync @voerkai18n/cli @voerkai18n/runtime @voerkai18n/vue @voerkai18n/openinula @voerkai18n/vite @voerkai18n/react @voerkai18n/utils @voerkai18n/vue2 @voerkai18n/babel voerkai18n-loader",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs"
"docs:preview": "vitepress preview docs",
"lint": "oxlint -c .oxlintrc.json"
},
"author": "wxzhang@126.com",
"license": "MIT",
Expand All @@ -29,17 +30,15 @@
"cross-env": "^7.0.3",
"dayjs": "^1.11.4",
"deepmerge": "^4.2.2",
"docsify": "^4.13.0",
"fs-extra": "^10.1.0",
"gulp": "^4.0.2",
"jest": "^27.5.1",
"logsets": "^1.3.1",
"oxlint": "^0.15.3",
"pnpm": "^7.9.0",
"prettier": "^2.7.1",
"semver": "^7.5.4",
"shelljs": "^0.8.5",
"turbo": "^2.1.2",
"vinyl": "^2.2.1",
"vitepress": "^1.5.0",
"yalc": "1.0.0-pre.53",
"yorkie": "^2.0.0"
Expand All @@ -48,7 +47,7 @@
"tips": "请安装JsonComments插件,详见https://github.com/zhangfisher/json_comments_extension",
"package.json": {
"scripts.test:runtime": "运行@voerkai18n/runtime单元测试",
"scripts.build:all": "构建所有包",
"scripts.build:all": "构建所有包",
"scripts.changeset": "当更新后执行以更新变更历史",
"scripts.sync": "同步淘宝镜像",
"scripts.release:all": "一健自动化发布所有包"
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/generateCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const ISO639 = require("iso-639-1-zh");
const fs = require("fs");

console.log(ISO639.getAllCodes()) // '中文'


const langTypes = []

fs.writeFileSync("lngTypes",ISO639.getAllCodes().join("' | '"))

console.log(ISO639.getZhName('zh')) // '中文'
console.log(ISO639.getZhName('es')) // '西班牙语'
console.log(ISO639.getLanguages(['en', 'es']))

26 changes: 26 additions & 0 deletions packages/cli/lngTypes
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
type LanguageCodes = 'aa' | 'ab' | 'ae' | 'af' | 'ak' | 'am' | 'an' | 'ar' | 'as' | 'av' | 'ay' | 'az'
| 'ba' | 'be' | 'bg' | 'bh' | 'bi' | 'bm' | 'bn' | 'bo' | 'br' | 'bs'
| 'ca' | 'ce' | 'ch' | 'co' | 'cr' | 'cs' | 'cu' | 'cv' | 'cy'
| 'da' | 'de' | 'dv' | 'dz'
| 'ee' | 'el' | 'en' | 'eo' | 'es' | 'et' | 'eu'
| 'fa' | 'ff' | 'fi' | 'fj' | 'fo' | 'fr' | 'fy'
| 'ga' | 'gd' | 'gl' | 'gn' | 'gu' | 'gv'
| 'ha' | 'he' | 'hi' | 'ho' | 'hr' | 'ht' | 'hu' | 'hy' | 'hz'
| 'ia' | 'id' | 'ie' | 'ig' | 'ii' | 'ik' | 'io' | 'is' | 'it' | 'iu'
| 'ja' | 'jv'
| 'ka' | 'kg' | 'ki' | 'kj' | 'kk' | 'kl' | 'km' | 'kn' | 'ko' | 'kr' | 'ks' | 'ku' | 'kv' | 'kw' | 'ky'
| 'la' | 'lb' | 'lg' | 'li' | 'ln' | 'lo' | 'lt' | 'lu' | 'lv'
| 'mg' | 'mh' | 'mi' | 'mk' | 'ml' | 'mn' | 'mr' | 'ms' | 'mt' | 'my'
| 'na' | 'nb' | 'nd' | 'ne' | 'ng' | 'nl' | 'nn' | 'no' | 'nr' | 'nv' | 'ny'
| 'oc' | 'oj' | 'om' | 'or' | 'os'
| 'pa' | 'pi' | 'pl' | 'ps' | 'pt'
| 'qu'
| 'rm' | 'rn' | 'ro' | 'ru' | 'rw'
| 'sa' | 'sc' | 'sd' | 'se' | 'sg' | 'si' | 'sk' | 'sl' | 'sm' | 'sn' | 'so' | 'sq' | 'sr' | 'ss' | 'st' | 'su' | 'sv' | 'sw'
| 'ta' | 'te' | 'tg' | 'th' | 'ti' | 'tk' | 'tl' | 'tn' | 'to' | 'tr' | 'ts' | 'tt' | 'tw' | 'ty'
| 'ug' | 'uk' | 'ur' | 'uz'
| 've' | 'vi' | 'vo'
| 'wa' | 'wo'
| 'xh'
| 'yi' | 'yo'
| 'za' | 'zh' | 'zu'
1 change: 1 addition & 0 deletions packages/cli/lngs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["aa","ab","ae","af","ak","am","an","ar","as","av","ay","az","ba","be","bg","bi","bm","bn","bo","br","bs","ca","ce","ch","co","cr","cs","cu","cv","cy","da","de","dv","dz","ee","el","en","eo","es","et","eu","fa","ff","fi","fj","fo","fr","fy","ga","gd","gl","gn","gu","gv","ha","he","hi","ho","hr","ht","hu","hy","hz","ia","id","ie","ig","ii","ik","io","is","it","iu","ja","jv","ka","kg","ki","kj","kk","kl","km","kn","ko","kr","ks","ku","kv","kw","ky","la","lb","lg","li","ln","lo","lt","lu","lv","mg","mh","mi","mk","ml","mn","mr","ms","mt","my","na","nb","nd","ne","ng","nl","nn","no","nr","nv","ny","oc","oj","om","or","os","pa","pi","pl","ps","pt","qu","rm","rn","ro","ru","rw","sa","sc","sd","se","sg","si","sk","sl","sm","sn","so","sq","sr","ss","st","su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ty","ug","uk","ur","uz","ve","vi","vo","wa","wo","xh","yi","yo","za","zh","zu"]
7 changes: 6 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
"fs-extra": "^10.0.1",
"glob": "^7.2.0",
"gulp": "^4.0.2",
"iso-639-1": "^3.1.3",
"lcid": "^4.0.1",
"locale-code": "^2.0.2",
"logsets": "^1.3.10",
"md5": "^2.3.0",
"qs": "^6.10.3",
Expand All @@ -50,5 +52,8 @@
"through2": "^4.0.2",
"vinyl": "^2.2.1"
},
"lastPublish": "2023-03-30T08:53:48+08:00"
"lastPublish": "2023-03-30T08:53:48+08:00",
"devDependencies": {
"iso-639-1-zh": "^2.0.4"
}
}
26 changes: 13 additions & 13 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
"typings": "./dist/index.d.ts"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsup",
"release": "npm publish"
"test": "vitest",
"build": "tsup"
},
"author": "wxzhang",
"license": "MIT",
"dependencies": {
"flex-tools": "^1.4.11"
"asyncsignal": "^0.0.2",
"flex-tools": "^1.4.16",
"flexvars": "^1.0.5",
"ts-mixer": "^6.0.4"
},
"devDependencies": {
"@swc/core": "^1.3.44",
"@types/node": "^18.15.11",
"@vitest/coverage-c8": "^0.30.1",
"@swc/core": "^1.10.4",
"@types/node": "^22.10.3",
"@vitest/coverage-c8": "^0.33.0",
"esbuild-analyzer": "^0.2.0",
"jest": "^27.5.1",
"tsup": "^6.7.0",
"typescript": "^4.9.3",
"vitest": "^0.29.8"
},
"lastPublish": "2023-03-30T08:53:24+08:00"
"tsup": "^8.3.5",
"typescript": "^5.7.2",
"vitest": "^2.1.8"
}
}
60 changes: 60 additions & 0 deletions packages/runtime/src/__tests__/_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { VoerkaI18nLanguageLoader } from '@/types'
import { VoerkaI18nScope, VoerkaI18nScopeOptions } from '../scope'
import { VoerkaI18nManager } from "@/manager"


export function createVoerkaI18nScope(opts?:Partial<VoerkaI18nScopeOptions>): VoerkaI18nScope {
return new VoerkaI18nScope(Object.assign({
id: 'test-scope',
debug: false,
library: false,
languages: {
zh: { name: 'Chinese', title: '中文', fallback: 'en', active: true,default: true },
en: { name: 'English', title: 'English'}
},
fallback: "en",
messages: {
en: { message: 'Hello' },
zh: { message: '你好' }
},
idMap: {},
storage: undefined,
formatters: {},
ready: () => {},
}, opts))
}


export function resetVoerkaI18n() {
try{

if(globalThis.VoerkaI18n){
globalThis.VoerkaI18n.clearLanguage()
}

// @ts-ignore
delete globalThis.__VoerkaI18nScopes__
// @ts-ignore
delete globalThis.VoerkaI18n
VoerkaI18nManager.instance = undefined

}catch{}
}


export function getTestStorage(init?:string){
let saveLanguage:string | undefined= init
return {
get() { return saveLanguage},
set(_:string,value:string){saveLanguage = value},
remove(){ saveLanguage = undefined }
}

}


export function getTestLanguageLoader(patchMsgs?:Record<string,any>):VoerkaI18nLanguageLoader{
return async (language:string,scope:VoerkaI18nScope)=>{
return Object.assign({},patchMsgs)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* 格式化器基本功能测试
*/
import {test,vi,describe,expect,afterAll,beforeAll, beforeEach} from 'vitest'
import { VoerkaI18nScope } from '../scope'
import { VoerkaI18nScope } from '../../scope'
import { VoerkaI18nFormatterRegistry } from '../formatterRegistry';
import { default as inlineFormatters } from '../formatters';
import { createI18nScope, mergeFormattersConfigs } from './utils';
import { messages,zhMessages,enMessages,formatters } from './utils/testData';
import { default as inlineFormatters } from '../../formatters';
import { createI18nScope, mergeFormattersConfigs } from '../data';
import { messages,zhMessages,enMessages,formatters } from '../data/testData';

let scope:VoerkaI18nScope;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


import {test,vi,describe,expect,afterAll,beforeAll, beforeEach} from 'vitest'
import { VoerkaI18nScope } from '../scope'
import { VoerkaI18nManager } from '../manager';
import { InvalidLanguageError } from '../errors';
import { createI18nScope } from './utils';
import { messages,zhMessages,enMessages } from './utils/testData';
import { VoerkaI18nScope } from '../../scope'
import { VoerkaI18nManager } from '../../manager';
import { VoerkaI18nInvalidLanguageError } from '../../errors';
import { createI18nScope } from '../data';
import { messages,zhMessages,enMessages } from '../data/testData';

let scope:VoerkaI18nScope;

Expand All @@ -25,10 +25,10 @@ describe("VoerkaI18n实例与语言切换", () => {
expect(scope.activeLanguage).toBe("zh")
expect(scope.defaultLanguage).toBe("zh")
expect(scope.messages).toEqual(messages)
expect(scope.default).toEqual(zhMessages)
expect(scope.current).toEqual(zhMessages)
expect(scope.defaultMessages).toEqual(zhMessages)
expect(scope.activeMessages).toEqual(zhMessages)
// 全局管理器
expect(scope.global).toBeInstanceOf(VoerkaI18nManager)
expect(scope.manager).toBeInstanceOf(VoerkaI18nManager)
})
test("切换语言", () => {
return new Promise<void>((resolve)=>{
Expand All @@ -37,8 +37,8 @@ describe("VoerkaI18n实例与语言切换", () => {
expect(scope.activeLanguage).toBe("en")
expect(scope.defaultLanguage).toBe("zh")
expect(scope.messages).toEqual(messages)
expect(scope.default).toEqual(zhMessages)
expect(scope.current).toEqual(enMessages)
expect(scope.defaultMessages).toEqual(zhMessages)
expect(scope.activeMessages).toEqual(enMessages)
resolve()
})
scope.change("en")
Expand All @@ -49,19 +49,19 @@ describe("VoerkaI18n实例与语言切换", () => {
try{
await scope.change("xn")
}catch(e){
expect(e).toBeInstanceOf(InvalidLanguageError)
expect(e).toBeInstanceOf(VoerkaI18nInvalidLanguageError)
}
})
test("指定了默认信息加载器时,切换到不存在的语言时从远程加载", async () => {
scope.global.registerDefaultLoader(async function(newLanguage:string,curScope){
scope.manager.registerDefaultLoader(async function(newLanguage:string,curScope){
expect(newLanguage).toBe("de")
expect(curScope).toBe(scope)
return {
hello:"[DE]hello"
}
})
await scope.change("de")
expect((scope.current as any)['hello']).toEqual("[DE]hello")
expect((scope.activeMessages as any)['hello']).toEqual("[DE]hello")
})

test("全局切换语言", () => {
Expand All @@ -79,8 +79,8 @@ describe("VoerkaI18n实例与语言切换", () => {
expect(scope.activeLanguage).toBe("en")
expect(scope.defaultLanguage).toBe("zh")
expect(scope.messages).toEqual(messages)
expect(scope.default).toEqual(zhMessages)
expect(scope.current).toEqual(enMessages)
expect(scope.defaultMessages).toEqual(zhMessages)
expect(scope.activeMessages).toEqual(enMessages)
event++
if(event==2) resolve()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
beforeAll,
beforeEach,
} from "vitest";
import { VoerkaI18nScope } from "../scope";
import { VoerkaI18nTranslate } from "../types";
import { createI18nScope } from "./utils";
import { VoerkaI18nScope } from "../../scope";
import { VoerkaI18nTranslate } from "../../types";
import { createI18nScope } from "../data";

let scope: VoerkaI18nScope;
let t: VoerkaI18nTranslate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@


import {test,vi,describe,expect,afterAll,beforeAll, beforeEach} from 'vitest'
import { VoerkaI18nScope } from '../scope'
import { VoerkaI18nManager } from '../manager';
import { VoerkaI18nTranslate } from '../types';
import { InvalidLanguageError } from '../errors';
import { createI18nScope } from './utils';
import { messages,zhMessages,enMessages } from './utils/testData';
import { VoerkaI18nScope } from '../../scope'
import { VoerkaI18nManager } from '../../manager';
import { VoerkaI18nTranslate } from '../../types';
import { VoerkaI18nInvalidLanguageError } from '../../errors';
import { createI18nScope } from '../data';
import { messages,zhMessages,enMessages } from '../data/testData';

let scope:VoerkaI18nScope;
let t:VoerkaI18nTranslate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
beforeAll,
beforeEach,
} from "vitest";
import { VoerkaI18nScope } from "../scope";
import { VoerkaI18nTranslate } from "../types";
import { createI18nScope } from "./utils";
import { VoerkaI18nScope } from "../../scope";
import { VoerkaI18nTranslate } from "../../types";
import { createI18nScope } from "../data";

let scope: VoerkaI18nScope;
let t: VoerkaI18nTranslate;
Expand Down
Loading

0 comments on commit dc60903

Please sign in to comment.