feat: support i18n translate
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
813f761e47
commit
08ca3db67b
@ -1,3 +1,4 @@
|
||||
import i18m from '@ms/i18n'
|
||||
import { SourceMapBuilder } from 'source-map-builder'
|
||||
|
||||
const Arrays = Java.type('java.util.Arrays');
|
||||
@ -78,6 +79,9 @@ export class MiaoScriptConsole implements Console {
|
||||
console(...args) {
|
||||
this.info(args)
|
||||
}
|
||||
i18n(name: string, param?: { [key: string]: any }) {
|
||||
this.log(i18m.translate(name, param))
|
||||
}
|
||||
object(obj) {
|
||||
for (var i in obj) {
|
||||
this.info(i, '=>', obj[i])
|
||||
@ -101,9 +105,9 @@ export class MiaoScriptConsole implements Console {
|
||||
if (this.sourceMaps[fileName]) {
|
||||
var sourceMapping = this.sourceMaps[fileName].getSource(lineNumber, 0);
|
||||
if (sourceMapping) {
|
||||
if(lineNumber != sourceMapping.mapping.sourceLine){
|
||||
fileName = fileName.replace(".js", ".ts");
|
||||
lineNumber = sourceMapping.mapping.sourceLine;
|
||||
if (lineNumber != sourceMapping.mapping.sourceLine) {
|
||||
fileName = fileName.replace(".js", ".ts");
|
||||
lineNumber = sourceMapping.mapping.sourceLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
import '@ms/ployfill'
|
||||
let containerStartTime = new Date().getTime()
|
||||
console.log(`Initialization MiaoScript IOC Container @ms/container. Please wait...`)
|
||||
import i18n from '@ms/i18n'
|
||||
|
||||
let containerStartTime = Date.now();
|
||||
console.i18n("ms.core.ioc.initialize");
|
||||
import { plugin, server, task } from '@ms/api'
|
||||
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)
|
||||
class MiaoScriptCore {
|
||||
@ -38,16 +40,16 @@ class MiaoScriptCore {
|
||||
|
||||
loadPlugins() {
|
||||
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.build();
|
||||
this.pluginManager.load();
|
||||
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() {
|
||||
console.log("Disable MiaoScript Engine...")
|
||||
console.i18n("ms.core.engine.disable")
|
||||
this.pluginManager.disable();
|
||||
}
|
||||
}
|
||||
@ -82,15 +84,15 @@ function initialize() {
|
||||
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance());
|
||||
container.bind(plugin.PluginFolder).toConstantValue('plugins');
|
||||
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);
|
||||
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/plugin')
|
||||
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()
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ declare global {
|
||||
stack(err: Error): string[];
|
||||
sender(...args: any): void;
|
||||
console(...args: any): void;
|
||||
i18n(name: string, ...params: any[]);
|
||||
}
|
||||
}
|
||||
export { }
|
@ -1,10 +1,12 @@
|
||||
/// <reference path="./global.ts" />
|
||||
/// <reference types='@ms/nashorn' />
|
||||
import i18n from '@ms/i18n'
|
||||
let ployfillStartTime = new Date().getTime();
|
||||
console.info('Initialization Java Nashorn ployfill. Please wait...');
|
||||
i18n.initialize();
|
||||
console.i18n("ms.ployfill.initialize");
|
||||
require('./es5-ext');
|
||||
require('core-js');
|
||||
global.setGlobal('Proxy', require('./proxy').Proxy)
|
||||
global.setGlobal('XMLHttpRequest', require('./xml-http-request').XMLHttpRequest)
|
||||
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 { inject, provideSingleton, postConstruct, Container, ContainerInstance } from '@ms/container'
|
||||
import * as fs from '@ms/common/dist/fs'
|
||||
@ -27,9 +28,9 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
initialize() {
|
||||
if (this.pluginInstance !== null) {
|
||||
// 如果plugin不等于null 则代表是正式环境
|
||||
console.info(`Initialization MiaoScript Plugin System: ${this.pluginInstance} ...`)
|
||||
console.i18n('ms.plugin.initialize', { plugin: this.pluginInstance })
|
||||
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 files = []
|
||||
// load common plugin
|
||||
.concat(this.scanFloder(plugin))
|
||||
.concat(this.scanFolder(plugin))
|
||||
// load space plugin
|
||||
.concat(this.scanFloder(fs.file(plugin, this.serverType)))
|
||||
.concat(this.scanFolder(fs.file(plugin, this.serverType)))
|
||||
this.loadPlugins(files)
|
||||
}
|
||||
|
||||
@ -53,7 +54,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
|
||||
load(...args: any[]): void {
|
||||
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.runCatch(plugin, 'load')
|
||||
this.runCatch(plugin, `${this.serverType}load`)
|
||||
@ -62,7 +63,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
|
||||
enable(...args: any[]): void {
|
||||
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, `${this.serverType}enable`)
|
||||
this.registryCommand(plugin)
|
||||
@ -72,7 +73,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
|
||||
disable(...args: any[]): void {
|
||||
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, `${this.serverType}disable`)
|
||||
this.unregistryCommand(plugin)
|
||||
@ -110,12 +111,12 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
throw new Error(`Plugin ${JSON.stringify(name)} not exist!`)
|
||||
}
|
||||
|
||||
private scanFloder(plugin: any): string[] {
|
||||
private scanFolder(folder: any): string[] {
|
||||
var files = []
|
||||
console.info(`Scanning Plugins in ${plugin} ...`)
|
||||
this.checkUpdateFolder(plugin)
|
||||
console.i18n('ms.plugin.manager.scan', { folder })
|
||||
this.checkUpdateFolder(folder)
|
||||
// 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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user