我正在尝试在 ASPNetZero 框架中添加马来语语言,但其说法找不到模块./ms.js.
以下是我到目前为止已执行的步骤:
1.添加了用于马来语的XML文件
2.在DefaultLanguageCreator类中添加了新的语言
3.从菜单栏中选择我的语言。
有关详细错误,请参见下文:
core.js:14597 ERROR Error: Uncaught (in promise): Error: Cannot find module './ms.js'
Error: Cannot find module './ms.js'
at .*\.js$ namespace object:179
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)
at Object.onInvoke (core.js:16156)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138)
at zone.js:872
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:16147)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at zone.js:873
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:16147)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
defaultErrorLogger @ core.js:14597
push../node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ core.js:14645
next @ core.js:16628
schedulerFn @ core.js:12609
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:196
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ Subscriber.js:134
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ Subscriber.js:77
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:54
push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ Subject.js:47
push../node_modules/@angular/core/fesm5/core.js.EventEmitter.emit @ core.js:12593
(anonymous) @ core.js:16178
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:388
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:138
push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular @ core.js:16115
onHandleError @ core.js:16178
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.handleError @ zone.js:392
push../node_modules/zone.js/dist/zone.js.Zone.runGuarded @ zone.js:154
_loop_1 @ zone.js:677
api.microtaskDrainDone @ zone.js:686
drainMicroTaskQueue @ zone.js:602
Promise.then (async)
scheduleMicroTask @ zone.js:578
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:410
onScheduleTask @ zone.js:297
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:401
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:232
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMicroTask @ zone.js:252
scheduleResolveOrReject @ zone.js:862
resolvePromise @ zone.js:808
(anonymous) @ zone.js:724
webpackJsonpCallback @ bootstrap:25
(anonymous) @ 892.js:1
答案 0 :(得分:1)
在ASPNETZero中,日期选择器位于 ngx-bootstrap 中,因此在此lib中,他们使用moment.js, 您的三个步骤都正确,但是您错过了以下说明的步骤:
首先,在您的角度项目中,编辑此文件... \ angular \ src \ assets \ appconfig.json,并添加适合的localMapping转换(现在要进行en设置),不要忘记将此配置设置为appconfig。 production.json。
"localeMappings": {
"angular": [
{
"from": "ms",
"to": "en"
}
],
"moment": [
{
"from": "ms",
"to": "en"
},
...
],...
const cultureMap = {
'zh-Hans': 'zh-cn',
'es-MX': 'es',
'vi': 'en-gb',
'ms': 'ms'
// Add more here
};
设置您的模块图:
getModuleName(locale: string): string {
const moduleNameMap = {
'zh-Hans': 'zhCn',
'es-MX': 'es',
'pt-BR': 'ptBr',
'vi': 'enGb',
'ms': 'ms'
// Add more here
};
您可以像'ms':'en'那样映射您的文化,如果您这样做,您将获得格鲁吉亚类型的SPA日期选择器,但是如果您想更改您的日期选择器,您必须添加您的 i18n 覆盖,为此:
将此文件夹js文件添加到(... \ angular \ src \ assets \ ngx-bootstrap \ custom-i18n \ ms.js) 您可以在网上找到您的moment.js文化,或简单地编辑其他语言以获得合适的时刻。
最后,转到此文件: (... \ angular \ src \ assets \ ngx-bootstrap \ ngx-bootstrap-datepicker-config.service.ts) 并按如下所示更改此功能:
static registerNgxBootstrapDatePickerLocales(): Promise<boolean> {
if (abp.localization.currentLanguage.name === 'en') {
return Promise.resolve(true);
}
let supportedLocale = new NgxBootstrapLocaleMappingService().map(abp.localization.currentLanguage.name).toLowerCase();
let moduleLocaleName = new NgxBootstrapLocaleMappingService().getModuleName(abp.localization.currentLanguage.name);
if (abp.localization.currentLanguage.name === 'ms') {
return new Promise<boolean>((resolve, reject) => {
import(`assets/ngx-bootstrap/custom-i18n/ms.js`)
.then(module => {
defineLocale(abp.localization.currentLanguage.name.toLowerCase(), module[`msLocale`]);
resolve(true);
}, reject);
});
}
return new Promise<boolean>((resolve, reject) => {
import(`ngx-bootstrap/chronos/esm5/i18n/${supportedLocale}.js`)
.then(module => {
defineLocale(abp.localization.currentLanguage.name.toLowerCase(), module[`${moduleLocaleName}Locale`]);
resolve(true);
}, reject);
});
}
如您所见,在Promise ms.js文件导入函数中,我们将您的ms.js模块名称称为 msLocale ,这是在ms.js文件中声明的导出变量。
如果在此链接中找不到您的即时文化js文件: moment.js locales
只需编写自己,这是一个官方教程: moment.js customization