add typescript supports

This commit is contained in:
wxzhang 2023-01-10 14:39:48 +08:00
parent cdc732ada7
commit de90684f40
12 changed files with 204 additions and 208 deletions

View File

@ -1,6 +1,6 @@
{
"dependencies": {
"@voerkai18n/cli": "workspace:^1.0.6",
"@voerkai18n/runtime": "^1.0.0"
"@voerkai18n/runtime": "workspace:^1.0.0"
}
}

View File

@ -12,7 +12,7 @@
//"suppressImplicitAnyIndexErrors":true,
/* Language and Environment */
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": ["ES2015"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
//"lib": ["ES2015"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
"experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
"emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
@ -100,7 +100,7 @@
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
"allowJs": true,
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */

View File

@ -66,7 +66,7 @@ function generateFormatterFile(langName,{isTypeScript,formattersFolder,templateC
module.exports =async function compile(langFolder,opts={}){
const options = normalizeCompileOptions(opts);
let { moduleType,inlineRuntime,isTypeScript } = options;
let { moduleType,isTypeScript } = options;
// 如果自动则会从当前项目读取如果没有指定则会是esm
if(moduleType==="auto"){
moduleType = findModuleType(langFolder)
@ -139,26 +139,17 @@ module.exports =async function compile(langFolder,opts={}){
}
logger.log(t(" - idMap文件: {}"),path.basename(idMapFile))
// 嵌入运行时源码
if(inlineRuntime && !isTypeScript ){
const runtimeSourceFolder = path.join(require.resolve("@voerkai18n/runtime"),"../..")
fs.copyFileSync(
path.join(runtimeSourceFolder,"dist",`runtime.${moduleType === 'esm' ? 'mjs' : 'cjs'}`),
path.join(langFolder,"runtime.js")
)
logger.log(t(" - 运行时: {}"),"runtime.js")
}else{//如果不嵌入则需要安装运行时依赖
if(!isInstallDependent("@voerkai18n/runtime")){
installVoerkai18nRuntime(langFolder)
logger.log(t(" - 安装运行时: {}"),"@voerkai18n/runtime")
}else{
updateVoerkai18nRuntime(langFolder)
logger.log(t(" - 更新运行时:{}"),"@voerkai18n/runtime")
}
}
if(!isInstallDependent("@voerkai18n/runtime")){
installVoerkai18nRuntime(langFolder)
logger.log(t(" - 安装运行时: {}"),"@voerkai18n/runtime")
}else{
updateVoerkai18nRuntime(langFolder)
logger.log(t(" - 更新运行时:{}"),"@voerkai18n/runtime")
}
const templateContext = {
scopeId:projectPackageJson.name,
inlineRuntime,
languages,
defaultLanguage,
activeLanguage,

View File

@ -91,7 +91,7 @@ program
.command('compile')
.description(t('编译指定项目的语言包'))
.option('-D, --debug', t('输出调试信息'))
.option('--no-inline-runtime', t('不嵌入运行时源码'))
.option('-t, --typescript')
.option('-m, --moduleType [types]', t('输出模块类型,取值auto,esm,cjs'), 'esm')
.argument('[location]', t('工程项目所在目录'),"./")
.hook("preAction",async function(location){
@ -100,7 +100,7 @@ program
})
.action(async (location,options) => {
location = getProjectSourceFolder(location)
options.isTypeScript = isTypeScriptProject()
options.isTypeScript = options.typescript==undefined ? isTypeScriptProject() : options.typescript
const langFolder = path.join(location,"languages")
if(!fs.existsSync(langFolder)){
logger.error(t("语言包文件夹<{}>不存在",langFolder))

View File

@ -1,25 +1,17 @@
{{if moduleType === "esm"}}
import messageIds from "./idMap.js" // 语言ID映射文件
{{if inlineRuntime }}import runtime from "./runtime.js" // 运行时
const { translate,i18nScope } = runtime
import defaultFormatters from "./formatters/{{defaultLanguage}}.js" // 默认语言格式化器
{{if defaultLanguage === activeLanguage}}const activeFormatters = defaultFormatters{{else}}import activeFormatters from "./formatters/{{activeLanguage}}.js"{{/if}} // 激活语言格式化器
{{else}}import { translate,i18nScope } from "@voerkai18n/runtime"
import { translate,VoerkaI18nScope } from "@voerkai18n/runtime"
{{if defaultLanguage === activeLanguage}}const activeFormatters = defaultFormatters{{else}}import activeFormatters from "@voerkai18n/runtime/formatters/{{activeLanguage}}.js"{{/if}}
{{/if}}
import defaultMessages from "./{{defaultLanguage}}.js"
{{if defaultLanguage === activeLanguage}}const activeMessages = defaultMessages{{else}}import activeMessages from "./{{activeLanguage}}.js"{{/if}}
{{else}}
const messageIds = require("./idMap")
{{if inlineRuntime }}const { translate,i18nScope } = require("./runtime.js")
const defaultFormatters = require("./formatters/{{defaultLanguage}}.js")
{{if defaultLanguage === activeLanguage}}const activeFormatters = defaultFormatters{{else}}const activeFormatters = require("./formatters/{{activeLanguage}}.js"){{/if}}
{{else}}const { translate,i18nScope } = require("@voerkai18n/runtime")
const { translate,i18nScope } = require("@voerkai18n/runtime")
const defaultFormatters = require("@voerkai18n/runtime/formatters/{{defaultLanguage}}.js")
{{if defaultLanguage === activeLanguage}}const activeFormatters = defaultFormatters{{else}}const activeFormatters = require("@voerkai18n/runtime/formatters/{{activeLanguage}}.js"){{/if}}
{{/if}}
const defaultMessages = require("./{{defaultLanguage}}.js") // 默认语言包
{{if defaultLanguage === activeLanguage}}const activeMessages = defaultMessages{{else}}const activeMessages = require("./{{activeLanguage}}.js"){{/if}} {{/if}}
{{if defaultLanguage === activeLanguage}}const activeMessages = defaultMessages{{else}}const activeMessages = require("./{{activeLanguage}}.js"){{/if}}
{{/if}}
// 语言配置文件
const scopeSettings = {{@ settings}}
@ -34,7 +26,7 @@ const loaders = { {{each languages}}{{if $value.name !== defaultLanguage}}
}
// 语言作用域
const scope = new i18nScope({
const scope = new VoerkaI18nScope({
...scopeSettings, // languages,defaultLanguage,activeLanguage,namespaces,formatters
id : "{{scopeId}}", // 当前作用域的id自动取当前工程的package.json的name
debug : false, // 是否在控制台输出高度信息

View File

@ -1,12 +1,7 @@
import messageIds from "./idMap" // 语言ID映射文件
{{if inlineRuntime && !isTypeScript }}import runtime from "./runtime" // 运行时
const { translate,i18nScope } = runtime
import defaultFormatters from "./formatters/{{defaultLanguage}}" // 默认语言格式化器
{{if defaultLanguage === activeLanguage}}const activeFormatters = defaultFormatters{{else}}import activeFormatters from "./formatters/{{activeLanguage}}"{{/if}} //
{{else}}import { translate,i18nScope } from "@voerkai18n/runtime"
import { translate,VoerkaI18nScope } from "@voerkai18n/runtime"
import defaultFormatters from "./formatters/{{defaultLanguage}}" // 默认语言格式化器
{{if defaultLanguage === activeLanguage}}const activeFormatters = defaultFormatters{{else}}import activeFormatters from "@voerkai18n/runtime/formatters/{{activeLanguage}}"{{/if}}
{{/if}}
import defaultMessages from "./{{defaultLanguage}}"
{{if defaultLanguage === activeLanguage}}const activeMessages = defaultMessages{{else}}import activeMessages from "./{{activeLanguage}}"{{/if}}
@ -23,7 +18,7 @@ const loaders = { {{each languages}}{{if $value.name !== defaultLanguage}}
}
// 语言作用域
const scope = new i18nScope({
const scope = new VoerkaI18nScope({
...scopeSettings, // languages,defaultLanguage,activeLanguage,namespaces,formatters
id : "{{scopeId}}", // 当前作用域的id自动取当前工程的package.json的name
debug : false, // 是否在控制台输出高度信息

View File

@ -1,130 +1,156 @@
declare global {
export type VoerkaI18nILanguageMessages = Record<string, string>
export interface VoerkaI18nLanguagePack {
[key: string]: VoerkaI18nILanguageMessages
}
export interface VoerkaI18nManagerSettings {
debug?: boolean
defaultLanguage: string
activeLanguage: string
formatters: VoerkI18nFormatters
languages: VoerkaI18nLanguage[]
}
export class VoerkaI18nManager {
constructor(settings: VoerkaI18nManagerSettings)
get settings(): Required<VoerkaI18nManagerSettings> // 配置参数
get scopes(): VoerkaI18nScope[] // 注册的报有i18nScope实例q
get activeLanguage(): string // 当前激活语言名称
get defaultLanguage(): string // 默认语言名称
get languages(): VoerkaI18nSupportedLanguages // 支持的语言列表
get formatters(): VoerkI18nFormatters // 内置格式化器{*:{$config,$types,...},zh:{$config,$types,...},en:{$config,$types,...}}
get defaultMessageLoader(): VoerkI18nLoader // 默认语言包加载器
// 通过默认加载器加载文件
loadMessagesFromDefaultLoader(newLanguage: string, scope: VoerkaI18nScope): Promise<VoerkaI18nILanguageMessages>
change(language: string): Promise<void>
register(scope: VoerkaI18nScope): Promise<void>
registerFormatter(name: string, formatter: VoerkI18nFormatter, options?: { language: string | string[] }): void
registerDefaultLoader(fn: VoerkI18nLoader): void
refresh(): Promise<void>
}
export type VoerkaLanguageMessages = Record<string,string>
export interface VoerkaLanguagePack {
[key: string]: VoerkaLanguageMessages
}
export interface VoerkaI18nManagerSettings {
debug?:boolean
defaultLanguage: string
activeLanguage : string
formatters : VoerkI18nFormatters
languages :VoerkaI18nLanguage[]
export type Voerkai18nIdMap = Record<string, number>
export interface VoerkaI18nLanguage {
name: string
title?: string
default?: boolean
fallback?: string
}
export interface VoerkaI18nSupportedLanguages {
[key: string]: VoerkaI18nLanguage
}
export type VoerkI18nFormatter = (value: string, ...args: any[]) => string
export type VoerkI18nFormatterConfigs = Record<string, any>
export type VoerkI18nFormatters = Record<string, ({
$types?: Record<string, VoerkI18nFormatter>
$config?: Record<string, string>
} & {
[key: string]: VoerkI18nFormatter
}) | (() => Promise<any>)>
export type VoerkI18nLoader = () => Awaited<Promise<any>>
export interface VoerkI18nLoaders {
[key: string]: VoerkI18nLoader
}
export interface VoerkaVoerkaI18nScopeOptions {
id?: string
debug?: boolean
languages: VoerkaI18nLanguage[]
defaultLanguage: string // 默认语言名称
activeLanguage: string // 当前语言名称
default: VoerkaI18nILanguageMessages // 默认语言包
messages: VoerkaI18nILanguageMessages // 当前语言包
idMap: Voerkai18nIdMap // 消息id映射列表
formatters: VoerkI18nFormatters // 当前作用域的格式化函数列表{<lang>: {$types,$config,[格式化器名称]: () => {},[格式化器名称]: () => {}}}
loaders: VoerkI18nLoaders; // 异步加载语言文件的函数列表
}
export var VoerkaI18n: VoerkaI18nManager
}
export class I18nManager{
constructor(settings:VoerkaI18nManagerSettings)
get settings():Required<VoerkaI18nManagerSettings> // 配置参数
get scopes():i18nScope[] // 注册的报有i18nScope实例q
get activeLanguage():string // 当前激活语言名称
get defaultLanguage():string // 默认语言名称
get languages():VoerkaI18nSupportedLanguages // 支持的语言列表
get formatters():VoerkI18nFormatters // 内置格式化器{*:{$config,$types,...},zh:{$config,$types,...},en:{$config,$types,...}}
get defaultMessageLoader():VoerkI18nLoader // 默认语言包加载器
// 通过默认加载器加载文件
loadMessagesFromDefaultLoader(newLanguage:string,scope:i18nScope):Promise<VoerkaLanguageMessages>
change(language:string):Promise<void>
register(scope:i18nScope):Promise<void>
registerFormatter(name:string,formatter:VoerkI18nFormatter,options?:{language:string | string[]}):void
registerDefaultLoader(fn:VoerkI18nLoader):void
refresh():Promise<void>
}
export class VoerkaI18nScope {
constructor(options: VoerkaVoerkaI18nScopeOptions, callback?: Function)
get id(): string // 作用域唯一id
get debug(): boolean // 调试开关
get defaultLanguage(): string // 默认语言名称
get activeLanguage(): string // 默认语言名称
get default(): VoerkaI18nILanguageMessages // 默认语言包
get messages(): VoerkaI18nILanguageMessages // 当前语言包
get idMap(): Voerkai18nIdMap // 消息id映射列表
get languages(): VoerkaI18nSupportedLanguages // 当前作用域支持的语言列表[{name,title,fallback}]
get loaders(): VoerkI18nLoaders // 异步加载语言文件的函数列表
get global(): VoerkaI18nManager // 引用全局VoerkaI18n配置注册后自动引用
get formatters(): VoerkI18nFormatters // 当前作用域的所有格式化器定义 {<语言名称>: {$types,$config,[格式化器名称]: () = >{},[格式化器名称]: () => {}}}
get activeFormatters(): VoerkI18nFormatters // 当前作用域激活的格式化器定义 {$types,$config,[格式化器名称]: () = >{},[格式化器名称]: () = >{}}
get activeFormatterConfig(): VoerkI18nFormatterConfigs // 当前格式化器合并后的配置参数,参数已经合并了全局格式化器中的参数
export type Voerkai18nIdMap = Record<string,number>
export interface VoerkaI18nLanguage{
name:string
title?:string
default?:boolean
fallback?:string
}
export interface VoerkaI18nSupportedLanguages {
[key :string]:VoerkaI18nLanguage
}
export type VoerkI18nFormatter = (value:string,...args:any[]) => string
export type VoerkI18nFormatterConfigs = Record<string,any>
export type VoerkI18nFormatters = Record<string,({
$types?:Record<string,VoerkI18nFormatter>
$config?:Record<string,string>
} & {
[key:string]:VoerkI18nFormatter
}) | (() => Awaited<Promise<any>>)>
export type VoerkI18nLoader = ()=>Awaited<Promise<any>>
export interface VoerkI18nLoaders {
[key :string]:VoerkI18nLoader
}
export interface I18nScopeOptions{
id?:string
debug?:boolean
languages:VoerkaI18nLanguage[]
defaultLanguage:string // 默认语言名称
activeLanguage:string // 当前语言名称
default:VoerkaLanguageMessages // 默认语言包
messages:VoerkaLanguageMessages // 当前语言包
idMap:Voerkai18nIdMap // 消息id映射列表
formatters:VoerkI18nFormatters // 当前作用域的格式化函数列表{<lang>: {$types,$config,[格式化器名称]: () => {},[格式化器名称]: () => {}}}
loaders:VoerkI18nLoaders; // 异步加载语言文件的函数列表
}
export class i18nScope {
constructor(options:I18nScopeOptions, callback?:Function)
get id():string // 作用域唯一id
get debug():boolean // 调试开关
get defaultLanguage():string // 默认语言名称
get activeLanguage():string // 默认语言名称
get default():VoerkaLanguageMessages // 默认语言包
get messages(): VoerkaLanguageMessages // 当前语言包
get idMap():Voerkai18nIdMap // 消息id映射列表
get languages():VoerkaI18nSupportedLanguages // 当前作用域支持的语言列表[{name,title,fallback}]
get loaders() :VoerkI18nLoaders // 异步加载语言文件的函数列表
get global():I18nManager // 引用全局VoerkaI18n配置注册后自动引用
get formatters():VoerkI18nFormatters // 当前作用域的所有格式化器定义 {<语言名称>: {$types,$config,[格式化器名称]: () = >{},[格式化器名称]: () => {}}}
get activeFormatters():VoerkI18nFormatters // 当前作用域激活的格式化器定义 {$types,$config,[格式化器名称]: () = >{},[格式化器名称]: () = >{}}
get activeFormatterConfig():VoerkI18nFormatterConfigs // 当前格式化器合并后的配置参数,参数已经合并了全局格式化器中的参数
/**
*
* @param {*} callback
*/
register(callback:Function):void
/**
/**
*
* @param {*} callback
*/
register(callback: Function): void
/**
*
*/
registerFormatter(name:string, formatter:VoerkI18nFormatter, { language , global }:{language:string | string[] , global:boolean}):void
registerFormatter(name: string, formatter: VoerkI18nFormatter, { language, global }: { language: string | string[], global: boolean }): void
/**
*
*/
registerFormatters(formatters:VoerkI18nFormatters,asGlobal?:boolean):void
/**
*
*/
registerDefaultLoader(fn:Function):void
/**
*
* @param {*} language
* @returns
*/
getLanguage(language:string):VoerkaLanguageMessages
hasLanguage(language:string):boolean
refresh(newLanguage:string):Promise<void>
on():void
off():void
offAll():void
change(language:string):Promise<void>
registerFormatters(formatters: VoerkI18nFormatters, asGlobal?: boolean): void
/**
*
*/
registerDefaultLoader(fn: Function): void
/**
*
* @param {*} language
* @returns
*/
getLanguage(language: string): VoerkaI18nILanguageMessages
hasLanguage(language: string): boolean
refresh(newLanguage: string): Promise<void>
on(): void
off(): void
offAll(): void
change(language: string): Promise<void>
}
export type VoerkI18nFormatterConfigs = Record<string, any>
// 翻译函数
export var translate: {
(message: string, ...args: (string | Function)[]): string
(message: string, vars?: Record<string, any>): string
}
export interface CreateFormatterOptions {
normalize?: (value: any) => any // 对输入值进行规范化处理,如进行时间格式化时,为了提高更好的兼容性,支持数字时间戳/字符串/Date等需要对输入值进行处理如强制类型转换等
params?: string[] | null // 可选的声明参数顺序如果是变参的则需要传入null
configKey?: string // 声明该格式化器在$config中的路径支持简单的使用.的路径语法
}
export type Primitive = string | number | boolean | null | undefined
export declare type translate =((message:string,...args:(string | Function)[])=>string)
| ((message:string,vars:Record<string,any>)=>string)
export interface FormatterDefine {
(this: VoerkI18nFormatterConfigs, value: any, ...args: Primitive[]): string
(this: VoerkI18nFormatterConfigs, value: any, arg1: Primitive, $config: VoerkI18nFormatterConfigs): string
(this: VoerkI18nFormatterConfigs, value: any, arg1: Primitive, arg2: Primitive, $config: VoerkI18nFormatterConfigs): string
(this: VoerkI18nFormatterConfigs, value: any, arg1: Primitive, arg2: Primitive, arg3: Primitive, $config: VoerkI18nFormatterConfigs): string
configurable?: boolean
}
// 创建格式化器
export type CreateFormatterType = (fn: Function, options: CreateFormatterOptions, defaultParams: Record<string, any>) => FormatterDefine
export var createFormatter: CreateFormatterType
export var Formatter: CreateFormatterType
export type CreateFlexFormatterType = (fn: Function, options: CreateFormatterOptions, defaultParams: Record<string, any>) => FormatterDefine
export var createFlexFormatter: CreateFlexFormatterType
export var FlexFormatter: CreateFlexFormatterType
export var getDataTypeName:(value:any) => string
export var toDate: (value: any) => Date | number
export var toNumber: (value: any,defaultValue:number) => number
export var toBoolean: (value: any) => boolean
declare global {
var VoerkaI18n:I18nManager
var t:((message:string,...args:(string | Function)[])=>string)
| ((message:string,vars:Record<string,any>)=>string)
}

View File

@ -1,12 +1,10 @@
const {DataTypes,getDataTypeName,isPlainObject,isFunction,isNumber,isNothing,deepMerge,deepMixin} = require("./utils")
const {getInterpolatedVars,replaceInterpolatedVars} = require("./interpolate")
const {DataTypes,getDataTypeName,isFunction,deepMerge,toBoolean} = require("./utils")
const {createFormatter,Formatter,FlexFormatter,createFlexFormatter} = require("./formatter")
const { toDate } = require("./datatypes/datetime")
const { toNumber } = require("./datatypes/numeric")
const EventEmitter = require("./eventemitter")
const inlineFormatters = require("./formatters")
const i18nScope = require("./scope")
const VoerkaI18nScope = require("./scope")
const { translate } = require("./translate")
// 默认语言配置
@ -36,19 +34,19 @@ const defaultLanguageSettings = {
* VoerkaI18n.off("change",(language)=>{})
*
* */
class I18nManager extends EventEmitter{
class VoerkaI18nManager extends EventEmitter{
constructor(settings={}){
super()
if(I18nManager.instance!=null){
return I18nManager.instance;
if(VoerkaI18nManager.instance!=null){
return VoerkaI18nManager.instance;
}
I18nManager.instance = this;
VoerkaI18nManager.instance = this;
this._settings = deepMerge(defaultLanguageSettings,settings)
this._scopes=[] // 保存i18nScope实例
this._scopes=[] // 保存VoerkaI18nScope实例
this._defaultMessageLoader = null // 默认语言包加载器
}
get settings(){ return this._settings } // 配置参数
get scopes(){ return this._scopes } // 注册的报有i18nScope实例q
get scopes(){ return this._scopes } // 注册的报有VoerkaI18nScope实例q
get activeLanguage(){ return this._settings.activeLanguage} // 当前激活语言 名称
get defaultLanguage(){ return this._settings.defaultLanguage} // 默认语言名称
get languages(){ return this._settings.languages} // 支持的语言列表
@ -100,8 +98,8 @@ const defaultLanguageSettings = {
* @param {*} scope
*/
async register(scope){
if(!(scope instanceof i18nScope)){
throw new TypeError("Scope must be an instance of I18nScope")
if(!(scope instanceof VoerkaI18nScope)){
throw new TypeError("Scope must be an instance of VoerkaI18nScope")
}
this._scopes.push(scope)
await scope.refresh(this.activeLanguage)
@ -158,20 +156,14 @@ const defaultLanguageSettings = {
}
module.exports ={
isNumber,
isNothing,
isPlainObject,
isFunction,
module.exports ={
toDate,
toNumber,
deepMerge,
deepMixin,
getInterpolatedVars,
replaceInterpolatedVars,
I18nManager,
toBoolean,
deepMerge,
VoerkaI18nManager,
translate,
i18nScope,
VoerkaI18nScope,
createFormatter,
Formatter,
createFlexFormatter,

View File

@ -4,12 +4,12 @@
"description": "核心运行时",
"main": "./dist/index.cjs",
"module": "./dist/index.esm.js",
"types":"./index.d.ts",
"typings":"./index.d.ts",
"homepage": "https://gitee.com/zhangfisher/voerka-i18n",
"repository": {
"type": "git",
"url": "git+https://gitee.com/zhangfisher/voerka-i18n.git"
},
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c",

View File

@ -32,25 +32,25 @@ export default [
terser()
],
external:["@babel/runtime"]
},
{
input: './index.js',
output: [
{
file: 'dist/runtime.cjs',
exports:"auto",
format:"cjs",
sourcemap:true
},
{
file: 'dist/runtime.mjs',
exports:"default",
format:"esm",
sourcemap:true
}
],
plugins:[
commonjs()
]
}
// {
// input: './index.js',
// output: [
// {
// file: 'dist/runtime.cjs',
// exports:"auto",
// format:"cjs",
// sourcemap:true
// },
// {
// file: 'dist/runtime.mjs',
// exports:"default",
// format:"esm",
// sourcemap:true
// }
// ],
// plugins:[
// commonjs()
// ]
// }
]

View File

@ -1,6 +1,6 @@
const { DataTypes,isPlainObject, isFunction, getByPath, deepMixin,deepClone } = require("./utils");
module.exports = class i18nScope {
module.exports = class VoerkaI18nScope {
constructor(options = {}, callback) {
this._id = options.id || Date.now().toString() + parseInt(Math.random() * 1000);
this._debug = options.debug == undefined ? process && process.env && process.env.NODE_ENV === "development" : options.debug; // 当出错时是否在控制台台输出错误信息
@ -24,8 +24,8 @@ module.exports = class i18nScope {
this._initiLanguages()
// 如果不存在全局VoerkaI18n实例说明当前Scope是唯一或第一个加载的作用域则自动创建全局VoerkaI18n实例
if (!globalThis.VoerkaI18n) {
const { I18nManager } = require("./");
globalThis.VoerkaI18n = new I18nManager({
const { VoerkaI18nManager } = require("./");
globalThis.VoerkaI18n = new VoerkaI18nManager({
debug : this._debug,
defaultLanguage: this._defaultLanguage,
activeLanguage : this._activeLanguage,

View File

@ -414,9 +414,9 @@ function deepMerge(toObj,formObj,options={}){
*/
function updateVoerkai18nRuntime(srcPath){
const projectFolder = getProjectRootFolder(srcPath || process.cwd())
if(fs.existsSync("pnpm-lock.yaml")){
if(fs.existsSync(path.join(projectFolder,"pnpm-lock.yaml"))){
shelljs.exec("pnpm upgrade --latest @voerkai18n/runtime")
}else if(fs.existsSync("yarn.lock")){
}else if(fs.existsSync(path.join(projectFolder,"yarn.lock"))){
shelljs.exec("yarn upgrade @voerkai18n/runtime")
}else{
shelljs.exec("npm update --save @voerkai18n/runtime")