Aurelia项目使用TypeScript(tsc 2.1.4),JSPM和aurelia-materialize-bridge@0.20.6。
项目是多语言的(翻译在数据库中并在需要时通过“LanguageService”注入)所以我们也需要 MdDatePicker 的翻译实例。
我找到了一种方法,如何翻译属性,如 monthsFull , monthsShort ,今天 ......每个MdDatePicker实例(pickadate.js picker's)在视图/视图模型中以这种方式实际的属性:
<input md-datepicker="container: body;value.two-way: fromDate;"
md-datepicker.ref="dpickerFrom"
type="date" placeholder=${dtPickTitle} />
attached(
var picker = (<any>this).dpickerFrom.picker;
var settings = picker.component.settings;
settings.monthsFull = this.languageService.datePickerTran.monthsFull; // e.g. [ 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' ]
settings.today = this.languageService.datePickerTran.today; //e.g."Heute"
picker.render(true);
)
我试图在App.ts中全局覆盖所需的属性:
import * as bridge from 'aurelia-materialize-bridge';
constructor (){
bridge.MdDatePicker.prototype;//Can't find where to put translations
}
但我找不到所需。
这是正确的方法吗? 考虑给定平台,有没有办法在所有实例的一个地方设置此属性(默认值)?
答案 0 :(得分:1)
我告诉OP将我的答案发回这里。所以这里......: - )
此处有一个options
绑定:https://github.com/aurelia-ui-toolkits/aurelia-materialize-bridge/blob/master/src/datepicker/datepicker.js#L19
结果用于在此处初始化datepicker:https://github.com/aurelia-ui-toolkits/aurelia-materialize-bridge/blob/master/src/datepicker/datepicker.js#L76
现在,如果你访问了链接,你可能在这里看到了一个i18n配置的注释示例(德语字符串):https://github.com/aurelia-ui-toolkits/aurelia-materialize-bridge/blob/master/src/datepicker/datepicker.js#L47-L60
所以,如果你在options
绑定中设置i18n属性,它可以工作..
<input
md-datepicker="container: body; value.two-way: selectedDate; options.bind:i18nOptions;"
type="date" placeholder="pick a date"/>
i18nOptions
可能在哪里:
{
selectMonths: true, // Creates a dropdown to control month
selectYears: 15, // Creates a dropdown of 15 years to control year
monthsFull: [ 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' ],
monthsShort: [ 'Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez' ],
weekdaysFull: [ 'Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag' ],
weekdaysShort: [ 'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa' ],
today: 'Heute',
clear: 'Löschen',
close: 'Schließen',
firstDay: 1,
format: 'dddd, dd. mmmm yyyy',
formatSubmit: 'yyyy/mm/dd'
}
我绝对想让它更明确。
答案 1 :(得分:0)
我有类似的答案
在我看来,我有
<div class="input-field col s6">
@Html.EditorFor(model => model.FECHAI_VIG, new { htmlAttributes = new { @id = "fechai_vig", @class = "form-control datepicker", @onkeyup = "borrar(this);" } })
@Html.LabelFor(model => model.FECHAI_VIG, "De", htmlAttributes: new { @class = "active" })
</div>
在剧本中
<script>
var elemth = document.querySelector('#fechai_vig');
var optionsth = {
format: 'dd/mm/yyyy',
i18n: {
clear: 'Limpiar',
today: 'Hoy',
done: 'Seleccionar',
previousMonth: '‹',
nextMonth: '›',
months: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
monthsShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
weekdaysShort: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'],
weekdays: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
weekdaysAbbrev: ['D', 'L', 'M', 'X', 'J', 'V', 'S']
}
};
var instanceth = M.Datepicker.init(elemth, optionsth);
</script>