【发布时间】:2018-04-21 02:24:41
【问题描述】:
我在 Aurelia 中有以下自定义属性:
import { fireEvent } from '_utils/events'
import { autoinject, customAttribute, inject } from 'aurelia-framework'
import $ from 'jquery'
import { I18N } from 'aurelia-i18n'
import 'Modernizr'
import 'pickadate/lib/compressed/picker'
import 'pickadate/lib/compressed/picker.date'
@customAttribute('datepicker')
@inject(Element)
@autoinject
export class DatePicker {
// public i18N: I18N
private usePickADate: boolean
constructor (private element: Element, private i18n: I18N) {
this.i18n = i18n
this.usePickADate = !Modernizr.inputtypes.date
$(this.element).pickadate({
weekdaysShort: ['Ss', 'Mm', 'Tt', 'Ww', 'Th', 'Ff', 'Ss'],
showMonthsShort: true,
format: i18n.tr('general.date-format')
})
}
public attached () {
if (this.usePickADate) {
$(this.element).pickadate()
.on('change', (e: any) => {
fireEvent(e.target, 'input')
})
}
}
public detached () {
if (this.usePickADate) {
$(this.element).pickadate('picker')
.off('change')
.stop()
}
}
}
这里我无法使用 i18n 进行翻译和本地化。我收到此错误:
内部错误:消息:无法读取未定义的属性“tr”
有什么问题?我该如何解决?
【问题讨论】:
标签: typescript localization aurelia i18next custom-attribute