feat: support i18n translate
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
2322de1e40
commit
2693a22bf0
@ -1,3 +1,4 @@
|
|||||||
|
import i18m from '@ms/i18n'
|
||||||
import { SourceMapBuilder } from 'source-map-builder'
|
import { SourceMapBuilder } from 'source-map-builder'
|
||||||
|
|
||||||
const Arrays = Java.type('java.util.Arrays');
|
const Arrays = Java.type('java.util.Arrays');
|
||||||
@ -78,6 +79,9 @@ export class MiaoScriptConsole implements Console {
|
|||||||
console(...args) {
|
console(...args) {
|
||||||
this.info(args)
|
this.info(args)
|
||||||
}
|
}
|
||||||
|
i18n(name: string, param?: { [key: string]: any }) {
|
||||||
|
this.log(i18m.translate(name, param))
|
||||||
|
}
|
||||||
object(obj) {
|
object(obj) {
|
||||||
for (var i in obj) {
|
for (var i in obj) {
|
||||||
this.info(i, '=>', obj[i])
|
this.info(i, '=>', obj[i])
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import '@ms/ployfill'
|
import '@ms/ployfill'
|
||||||
let containerStartTime = new Date().getTime()
|
import i18n from '@ms/i18n'
|
||||||
console.log(`Initialization MiaoScript IOC Container @ms/container. Please wait...`)
|
|
||||||
|
let containerStartTime = Date.now();
|
||||||
|
console.i18n("ms.core.ioc.initialize");
|
||||||
import { plugin, server, task } from '@ms/api'
|
import { plugin, server, task } from '@ms/api'
|
||||||
import { DefaultContainer as container, inject, provideSingleton, ContainerInstance, buildProviderModule } from '@ms/container'
|
import { DefaultContainer as container, inject, provideSingleton, ContainerInstance, buildProviderModule } from '@ms/container'
|
||||||
console.log('MiaoScript IOC Container @ms/container loading completed(' + (new Date().getTime() - containerStartTime) / 1000 + 's)!');
|
console.i18n("ms.core.ioc.completed", { time: (Date.now() - containerStartTime) / 1000 })
|
||||||
|
|
||||||
@provideSingleton(MiaoScriptCore)
|
@provideSingleton(MiaoScriptCore)
|
||||||
class MiaoScriptCore {
|
class MiaoScriptCore {
|
||||||
@ -38,16 +40,16 @@ class MiaoScriptCore {
|
|||||||
|
|
||||||
loadPlugins() {
|
loadPlugins() {
|
||||||
let loadPluginStartTime = new Date().getTime()
|
let loadPluginStartTime = new Date().getTime()
|
||||||
console.log(`Initialization MiaoScript Plugin System. Please wait...`)
|
console.i18n("ms.core.plugin.initialize")
|
||||||
this.pluginManager.scan(this.pluginFolder);
|
this.pluginManager.scan(this.pluginFolder);
|
||||||
this.pluginManager.build();
|
this.pluginManager.build();
|
||||||
this.pluginManager.load();
|
this.pluginManager.load();
|
||||||
this.pluginManager.enable();
|
this.pluginManager.enable();
|
||||||
console.log('MiaoScript Plugin System loading completed(' + (new Date().getTime() - loadPluginStartTime) / 1000 + 's)!');
|
console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 })
|
||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
console.log("Disable MiaoScript Engine...")
|
console.i18n("ms.core.engine.disable")
|
||||||
this.pluginManager.disable();
|
this.pluginManager.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,15 +84,15 @@ function initialize() {
|
|||||||
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance());
|
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance());
|
||||||
container.bind(plugin.PluginFolder).toConstantValue('plugins');
|
container.bind(plugin.PluginFolder).toConstantValue('plugins');
|
||||||
let type = detectServer();
|
let type = detectServer();
|
||||||
console.info(`Detect Compatible Server set ServerType to ${type} ...`)
|
console.i18n("ms.core.initialize.detect", { type });
|
||||||
container.bind(server.ServerType).toConstantValue(type);
|
container.bind(server.ServerType).toConstantValue(type);
|
||||||
console.log(`Initialization MiaoScript Package @ms/core @ms/${type} @ms/plugin. Please wait...`)
|
console.i18n("ms.core.package.initialize", { type });
|
||||||
require(`@ms/${type}`).default(container);
|
require(`@ms/${type}`).default(container);
|
||||||
require('@ms/plugin')
|
require('@ms/plugin')
|
||||||
container.load(buildProviderModule());
|
container.load(buildProviderModule());
|
||||||
console.log(`MiaoScript Package @ms/core @ms/${type} @ms/plugin loading completed(` + (new Date().getTime() - corePackageStartTime) / 1000 + 's)!');
|
console.i18n("ms.core.package.completed", { type, time: (Date.now() - corePackageStartTime) / 1000 });
|
||||||
let disable = container.get<MiaoScriptCore>(MiaoScriptCore).enable()
|
let disable = container.get<MiaoScriptCore>(MiaoScriptCore).enable()
|
||||||
console.log('MiaoScript ScriptEngine loading completed... Done (' + (new Date().getTime() - global.NashornEngineStartTime) / 1000 + 's)!');
|
console.i18n("ms.core.engine.completed", { time: (Date.now() - corePackageStartTime) / 1000 });
|
||||||
return disable;
|
return disable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ declare global {
|
|||||||
stack(err: Error): string[];
|
stack(err: Error): string[];
|
||||||
sender(...args: any): void;
|
sender(...args: any): void;
|
||||||
console(...args: any): void;
|
console(...args: any): void;
|
||||||
|
i18n(name: string, ...params: any[]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export { }
|
export { }
|
@ -1,10 +1,12 @@
|
|||||||
/// <reference path="./global.ts" />
|
/// <reference path="./global.ts" />
|
||||||
/// <reference types='@ms/nashorn' />
|
/// <reference types='@ms/nashorn' />
|
||||||
|
import i18n from '@ms/i18n'
|
||||||
let ployfillStartTime = new Date().getTime();
|
let ployfillStartTime = new Date().getTime();
|
||||||
console.info('Initialization Java Nashorn ployfill. Please wait...');
|
i18n.initialize();
|
||||||
|
console.i18n("ms.ployfill.initialize");
|
||||||
require('./es5-ext');
|
require('./es5-ext');
|
||||||
require('core-js');
|
require('core-js');
|
||||||
global.setGlobal('Proxy', require('./proxy').Proxy)
|
global.setGlobal('Proxy', require('./proxy').Proxy)
|
||||||
global.setGlobal('XMLHttpRequest', require('./xml-http-request').XMLHttpRequest)
|
global.setGlobal('XMLHttpRequest', require('./xml-http-request').XMLHttpRequest)
|
||||||
global.setGlobal('Blob', require('blob-polyfill').Blob)
|
global.setGlobal('Blob', require('blob-polyfill').Blob)
|
||||||
console.info('Java Nashorn ployfill loading completed... Cost (' + (new Date().getTime() - ployfillStartTime) / 1000 + 's)!');
|
console.i18n("ms.ployfill.completed", { time: (new Date().getTime() - ployfillStartTime) / 1000 });
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import i18n from '@ms/i18n'
|
||||||
import { plugin, server, command, event } from '@ms/api'
|
import { plugin, server, command, event } from '@ms/api'
|
||||||
import { inject, provideSingleton, postConstruct, Container, ContainerInstance } from '@ms/container'
|
import { inject, provideSingleton, postConstruct, Container, ContainerInstance } from '@ms/container'
|
||||||
import * as fs from '@ms/common/dist/fs'
|
import * as fs from '@ms/common/dist/fs'
|
||||||
@ -27,9 +28,9 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
initialize() {
|
initialize() {
|
||||||
if (this.pluginInstance !== null) {
|
if (this.pluginInstance !== null) {
|
||||||
// 如果plugin不等于null 则代表是正式环境
|
// 如果plugin不等于null 则代表是正式环境
|
||||||
console.info(`Initialization MiaoScript Plugin System: ${this.pluginInstance} ...`)
|
console.i18n('ms.plugin.initialize', { plugin: this.pluginInstance })
|
||||||
this.pluginMap = new Map()
|
this.pluginMap = new Map()
|
||||||
console.info(`${this.EventManager.mapEventName().toFixed(0)} ${this.serverType} Event Mapping Complate...`)
|
console.i18n('ms.plugin.event.map', { count: this.EventManager.mapEventName().toFixed(0), type: this.serverType });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,9 +38,9 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
var plugin = fs.file(root, folder)
|
var plugin = fs.file(root, folder)
|
||||||
var files = []
|
var files = []
|
||||||
// load common plugin
|
// load common plugin
|
||||||
.concat(this.scanFloder(plugin))
|
.concat(this.scanFolder(plugin))
|
||||||
// load space plugin
|
// load space plugin
|
||||||
.concat(this.scanFloder(fs.file(plugin, this.serverType)))
|
.concat(this.scanFolder(fs.file(plugin, this.serverType)))
|
||||||
this.loadPlugins(files)
|
this.loadPlugins(files)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
|
|
||||||
load(...args: any[]): void {
|
load(...args: any[]): void {
|
||||||
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
||||||
this.logStage(plugin, "Loading")
|
this.logStage(plugin, i18n.translate("ms.plugin.stage.load"))
|
||||||
this.loadConfig(plugin)
|
this.loadConfig(plugin)
|
||||||
this.runCatch(plugin, 'load')
|
this.runCatch(plugin, 'load')
|
||||||
this.runCatch(plugin, `${this.serverType}load`)
|
this.runCatch(plugin, `${this.serverType}load`)
|
||||||
@ -62,7 +63,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
|
|
||||||
enable(...args: any[]): void {
|
enable(...args: any[]): void {
|
||||||
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
||||||
this.logStage(plugin, "Enabling")
|
this.logStage(plugin, i18n.translate("ms.plugin.stage.enable"))
|
||||||
this.runCatch(plugin, 'enable')
|
this.runCatch(plugin, 'enable')
|
||||||
this.runCatch(plugin, `${this.serverType}enable`)
|
this.runCatch(plugin, `${this.serverType}enable`)
|
||||||
this.registryCommand(plugin)
|
this.registryCommand(plugin)
|
||||||
@ -72,7 +73,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
|
|
||||||
disable(...args: any[]): void {
|
disable(...args: any[]): void {
|
||||||
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
||||||
this.logStage(plugin, "Disabling")
|
this.logStage(plugin, i18n.translate("ms.plugin.stage.disable"))
|
||||||
this.runCatch(plugin, 'disable')
|
this.runCatch(plugin, 'disable')
|
||||||
this.runCatch(plugin, `${this.serverType}disable`)
|
this.runCatch(plugin, `${this.serverType}disable`)
|
||||||
this.unregistryCommand(plugin)
|
this.unregistryCommand(plugin)
|
||||||
@ -110,12 +111,12 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
throw new Error(`Plugin ${JSON.stringify(name)} not exist!`)
|
throw new Error(`Plugin ${JSON.stringify(name)} not exist!`)
|
||||||
}
|
}
|
||||||
|
|
||||||
private scanFloder(plugin: any): string[] {
|
private scanFolder(folder: any): string[] {
|
||||||
var files = []
|
var files = []
|
||||||
console.info(`Scanning Plugins in ${plugin} ...`)
|
console.i18n('ms.plugin.manager.scan', { folder })
|
||||||
this.checkUpdateFolder(plugin)
|
this.checkUpdateFolder(folder)
|
||||||
// must check file is exist maybe is a illegal symbolic link file
|
// must check file is exist maybe is a illegal symbolic link file
|
||||||
fs.list(plugin).forEach((file: any) => file.toFile().exists() ? files.push(file.toFile()) : void 0)
|
fs.list(folder).forEach((file: any) => file.toFile().exists() ? files.push(file.toFile()) : void 0)
|
||||||
return files
|
return files
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user