update docs
This commit is contained in:
parent
0f08a77555
commit
81f5968d39
@ -46,7 +46,7 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
title:"源代码",
|
||||
path: "https://gitee.com/zhangfisher/voerka-i18n"
|
||||
path: "https://github.com/zhangfisher/voerka-i18n"
|
||||
}
|
||||
],
|
||||
menus: {
|
||||
|
@ -8,7 +8,7 @@ sidebar: heading
|
||||
|
||||
## 获取源码
|
||||
|
||||
`voerkai18n`在Github和[Gitee](https://gitee.com/zhangfisher/voerka-i18n)上面开源。
|
||||
`voerkai18n`在[Github](https://github.com/zhangfisher/voerka-i18n)和[Gitee](https://gitee.com/zhangfisher/voerka-i18n)上面同步开源。
|
||||
|
||||
### 拉取源码
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
# 获取支持
|
||||
|
||||
- 通过Gitgee或Github提交[issues](https://github.com/zhangfisher/voerka-i18n/issues)
|
||||
- 提交Gitee[issues](https://gitee.com/zhangfisher/voerka-i18n/issues)
|
||||
- 提交Github[issues](https://github.com/zhangfisher/voerka-i18n/issues)
|
||||
- 国内用户可以加[QQ群](https://qm.qq.com/cgi-bin/qm/qr?k=jKyZR9KupT9Ith5ZsulB-i04OaJDkCwe&jump_from=webapi).
|
||||
|
@ -2,10 +2,10 @@
|
||||
| 包| 版本号| 最后更新|说明|
|
||||
| --- | :---:| --- |---|
|
||||
|**@voerkai18n/utils**|1.0.13|2022/08/20|公共工具库|
|
||||
|**@voerkai18n/runtime**|1.1.4|2022/08/24|核心运行时|
|
||||
|**@voerkai18n/runtime**|1.1.5|2022/08/25|核心运行时|
|
||||
|**@voerkai18n/formatters**|1.0.6|2022/04/15|格式化器,提供对要翻译文本的转换功能|
|
||||
|**@voerkai18n/react**|1.0.4|2022/04/16|React支持,提供语言切换等功能|
|
||||
|**@voerkai18n/cli**|1.0.37|2022/08/24|命令行工具,用来初始化/提取/编译/自动翻译等工具链|
|
||||
|**@voerkai18n/cli**|1.0.38|2022/08/25|命令行工具,用来初始化/提取/编译/自动翻译等工具链|
|
||||
|**@voerkai18n/babel**|1.0.24|2022/08/20|Babel插件,实现自动导入t函数和自动文本映射|
|
||||
|**@voerkai18n/vite**|1.0.13|2022/08/20|Vite插件,提供自动插入翻译函数和文本映射等功能|
|
||||
|**@voerkai18n/vue**|1.0.6|2022/08/20|Vue3插件,提供自动插件翻译函数和语言切换功能|
|
@ -1,4 +1,4 @@
|
||||
export default {
|
||||
module.exports = {
|
||||
"1": "支持的语言\t: {}",
|
||||
"2": "默认语言\t: {}",
|
||||
"3": "激活语言\t: {}",
|
||||
|
@ -1,4 +1,4 @@
|
||||
export default {
|
||||
module.exports = {
|
||||
"1": "Supported languages\t: {}",
|
||||
"2": "Default language\t: {}",
|
||||
"3": "Active language\t\t: {}",
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
// import { Formatter,FlexFormatter } from "./runtime"
|
||||
export default {
|
||||
module.exports = {
|
||||
// global : true, // 是否注册到全局,false只在当前scope生效
|
||||
// 直接对内置格式化器进行配置,请参阅官网文档
|
||||
// $config:{
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
// import { Formatter,FlexFormatter } from "./runtime"
|
||||
export default {
|
||||
module.exports = {
|
||||
// global : true, // 是否注册到全局,false只在当前scope生效
|
||||
// 直接对内置格式化器进行配置,请参阅官网文档
|
||||
// $config:{
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
// import { Formatter,FlexFormatter } from "./runtime"
|
||||
export default {
|
||||
module.exports = {
|
||||
// global : true, // 是否注册到全局,false只在当前scope生效
|
||||
// 直接对内置格式化器进行配置,请参阅官网文档
|
||||
// $config:{
|
||||
|
@ -1,4 +1,4 @@
|
||||
export default {
|
||||
module.exports = {
|
||||
"支持的语言\t: {}": 1,
|
||||
"默认语言\t: {}": 2,
|
||||
"激活语言\t: {}": 3,
|
||||
|
@ -1,13 +1,11 @@
|
||||
|
||||
import messageIds from "./idMap.js" // 语言ID映射文件
|
||||
import runtime from "./runtime.js" // 运行时
|
||||
const { translate,i18nScope } = runtime
|
||||
import defaultFormatters from "./formatters/zh.js" // 默认语言格式化器
|
||||
const activeFormatters = defaultFormatters // 激活语言格式化器
|
||||
const messageIds = require("./idMap")
|
||||
const { translate,i18nScope } = require("./runtime.js")
|
||||
const defaultFormatters = require("./formatters/zh.js")
|
||||
const activeFormatters = defaultFormatters
|
||||
|
||||
import defaultMessages from "./zh.js"
|
||||
const activeMessages = defaultMessages
|
||||
|
||||
const defaultMessages = require("./zh.js") // 默认语言包
|
||||
const activeMessages = defaultMessages
|
||||
|
||||
// 语言配置文件
|
||||
const scopeSettings = {
|
||||
@ -54,8 +52,6 @@ const scope = new i18nScope({
|
||||
// 翻译函数
|
||||
const scopedTtranslate = translate.bind(scope)
|
||||
|
||||
export {
|
||||
scopedTtranslate as t,
|
||||
scope as i18nScope
|
||||
}
|
||||
module.exports.t = scopedTtranslate
|
||||
module.exports.i18nScope = scope
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 判断是否是JSON对象
|
||||
* @param {*} obj
|
||||
@ -849,6 +851,7 @@ function getFormatter(scope, activeLanguage, name) {
|
||||
scope.activeFormatters,
|
||||
scope.formatters[fallbackLanguage], // 如果指定了回退语言时,也在该回退语言中查找
|
||||
scope.global.formatters[activeLanguage], // 适用于activeLanguage全局格式化器
|
||||
scope.global.formatters[fallbackLanguage],
|
||||
scope.global.formatters["*"], // 适用于所有语言的格式化器
|
||||
];
|
||||
for (const formatters of range) {
|
||||
@ -1659,8 +1662,8 @@ var en = {
|
||||
next : 'break' // 当出错时下一步的行为: break=中止;skip=忽略
|
||||
},
|
||||
fileSize:{
|
||||
brief: ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB","NB","DB"],
|
||||
whole:["Bytes", "Kilobytes", "Megabytes", "Gigabytes", "TeraBytes", "PetaBytes", "ExaBytes", "ZetaBytes", "YottaBytes","DoggaBytes"],
|
||||
brief : ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB","NB","DB"],
|
||||
whole : ["Bytes", "Kilobytes", "Megabytes", "Gigabytes", "TeraBytes", "PetaBytes", "ExaBytes", "ZetaBytes", "YottaBytes","DoggaBytes"],
|
||||
precision: 2 // 小数精度
|
||||
}
|
||||
},
|
||||
@ -1965,8 +1968,6 @@ const empty = Formatter$1(function(value,escapeValue,next,$config){
|
||||
{ value | error('ERROR:{ error}',) } == 显示error.constructor.name
|
||||
|
||||
|
||||
|
||||
|
||||
* @param {*} value
|
||||
* @param {*} escapeValue
|
||||
* @param {*} next 下一步的行为,取值,break,ignore
|
||||
@ -2114,6 +2115,7 @@ var scope = class i18nScope {
|
||||
typedFormatters: {},
|
||||
formatters : {},
|
||||
};
|
||||
this._initiLanguages();
|
||||
// 如果不存在全局VoerkaI18n实例,说明当前Scope是唯一或第一个加载的作用域,则自动创建全局VoerkaI18n实例
|
||||
if (!globalThis.VoerkaI18n) {
|
||||
const { I18nManager } = runtime;
|
||||
@ -2144,6 +2146,16 @@ var scope = class i18nScope {
|
||||
get activeFormatters() {return this._activeFormatters} // 当前作用域激活的格式化器定义 {$types,$config,[格式化器名称]: () = >{},[格式化器名称]: () = >{}}
|
||||
get activeFormatterConfig(){return this._activeFormatterConfig} // 当前格式化器合并后的配置参数,参数已经合并了全局格式化器中的参数
|
||||
|
||||
/**
|
||||
* 对输入的语言配置进行处理
|
||||
* - 将en配置为默认回退语言
|
||||
*/
|
||||
_initiLanguages(){
|
||||
Object.entries(this._languages).forEach(([name,language])=>{
|
||||
if(!language.fallback) language.fallback = "en";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 在全局注册作用域当前作用域
|
||||
* @param {*} callback 注册成功后的回调
|
||||
@ -2173,11 +2185,7 @@ var scope = class i18nScope {
|
||||
if (!isFunction$2(formatter) || typeof name !== "string") {
|
||||
throw new TypeError("Formatter must be a function");
|
||||
}
|
||||
language = Array.isArray(language)
|
||||
? language
|
||||
: language
|
||||
? language.split(",")
|
||||
: [];
|
||||
language = Array.isArray(language) ? language: language ? language.split(","): [];
|
||||
if (asGlobal) {
|
||||
this.global.registerFormatter(name, formatter, { language });
|
||||
} else {
|
||||
@ -2204,46 +2212,23 @@ var scope = class i18nScope {
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 注册默认文本信息加载器
|
||||
* @param {Function} 必须是异步函数或者是返回Promise
|
||||
*/
|
||||
registerDefaultLoader(fn) {
|
||||
this.global.registerDefaultLoader(fn);
|
||||
}
|
||||
/**
|
||||
* 获取指定语言信息
|
||||
* @param {*} language
|
||||
* @returns
|
||||
*/
|
||||
getLanguage(language) {
|
||||
let index = this._languages.findIndex((lng) => lng.name == language);
|
||||
if (index !== -1) return this._languages[index];
|
||||
}
|
||||
/**
|
||||
* 返回是否存在指定的语言
|
||||
* @param {*} language 语言名称
|
||||
* @returns
|
||||
*/
|
||||
hasLanguage(language) {
|
||||
return this._languages.indexOf((lang) => lang.name == language) !== -1;
|
||||
}
|
||||
/**
|
||||
* 回退到默认语言
|
||||
*/
|
||||
_fallback() {
|
||||
this._messages = this._default;
|
||||
this._activeLanguage = this.defaultLanguage;
|
||||
}
|
||||
/**
|
||||
* 初始化格式化器
|
||||
* 激活和默认语言的格式化器采用静态导入的形式,而没有采用异步块的形式,这是为了确保首次加载时的能马上读取,而不能采用延迟加载方式
|
||||
* _activeFormatters={$config:{...},$types:{...},[格式化器名称]:()=>{...},[格式化器名称]:()=>{...},...}}
|
||||
*/
|
||||
_initFormatters(newLanguage){
|
||||
_initFormatters(newLanguage){
|
||||
// 全局格式化器,用来注册到全局
|
||||
Object.entries(this._formatters).forEach(([langName,formatters])=>{
|
||||
if(formatters.global===true){
|
||||
this.registerFormatters({[langName]:formatters},true);
|
||||
}else if(isPlainObject$2(formatters.global)){
|
||||
this.registerFormatters({[langName]:formatters.global},true);
|
||||
}
|
||||
});
|
||||
this._activeFormatters = {};
|
||||
try {
|
||||
if (newLanguage in this._formatters) {
|
||||
if (newLanguage in this._formatters) {
|
||||
this._activeFormatters = this._formatters[newLanguage];
|
||||
} else {
|
||||
if (this._debug) console.warn(`Not initialize <${newLanguage}> formatters.`);
|
||||
@ -2302,6 +2287,39 @@ var scope = class i18nScope {
|
||||
}
|
||||
return this._activeFormatterConfig = options
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册默认文本信息加载器
|
||||
* @param {Function} 必须是异步函数或者是返回Promise
|
||||
*/
|
||||
registerDefaultLoader(fn) {
|
||||
this.global.registerDefaultLoader(fn);
|
||||
}
|
||||
/**
|
||||
* 获取指定语言信息
|
||||
* @param {*} language
|
||||
* @returns
|
||||
*/
|
||||
getLanguage(language) {
|
||||
let index = this._languages.findIndex((lng) => lng.name == language);
|
||||
if (index !== -1) return this._languages[index];
|
||||
}
|
||||
/**
|
||||
* 返回是否存在指定的语言
|
||||
* @param {*} language 语言名称
|
||||
* @returns
|
||||
*/
|
||||
hasLanguage(language) {
|
||||
return this._languages.indexOf((lang) => lang.name == language) !== -1;
|
||||
}
|
||||
/**
|
||||
* 回退到默认语言
|
||||
*/
|
||||
_fallback() {
|
||||
this._messages = this._default;
|
||||
this._activeLanguage = this.defaultLanguage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新当前语言包
|
||||
* @param {*} newLanguage
|
||||
@ -2740,5 +2758,5 @@ var runtime ={
|
||||
getDataTypeName
|
||||
};
|
||||
|
||||
export { runtime as default };
|
||||
//# sourceMappingURL=runtime.mjs.map
|
||||
module.exports = runtime;
|
||||
//# sourceMappingURL=runtime.cjs.map
|
||||
|
@ -1,4 +1,4 @@
|
||||
export default {
|
||||
module.exports = {
|
||||
"1": "支持的语言\t: {}",
|
||||
"2": "默认语言\t: {}",
|
||||
"3": "激活语言\t: {}",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@voerkai18n/cli",
|
||||
"version": "1.0.37",
|
||||
"version": "1.0.38",
|
||||
"description": "命令行工具,用来初始化/提取/编译/自动翻译等工具链",
|
||||
"main": "index.js",
|
||||
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",
|
||||
@ -50,5 +50,5 @@
|
||||
"devDependencies": {
|
||||
"@voerkai18n/autopublish": "workspace:^1.0.2"
|
||||
},
|
||||
"lastPublish": "2022-08-24T21:43:18+08:00"
|
||||
"lastPublish": "2022-08-25T22:07:13+08:00"
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@voerkai18n/runtime",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.5",
|
||||
"description": "核心运行时",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "dist/index.esm.js",
|
||||
@ -36,5 +36,5 @@
|
||||
"rollup-plugin-clear": "^2.0.7",
|
||||
"rollup-plugin-terser": "^7.0.2"
|
||||
},
|
||||
"lastPublish": "2022-08-24T21:43:00+08:00"
|
||||
"lastPublish": "2022-08-25T22:07:01+08:00"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user