Hou*_*dri 5 localization momentjs
我想在 moment.js 中创建我自己的语言环境,它的父级应该是阿拉伯语本地环境,但我只想更改为显示的数字格式0-9,而不是默认显示。
根据文档,我可以从以下开始:
moment.defineLocale('ar-sa-mine', {
parentLocale: 'ar-sa',
/*
here I need to specify the numeric: change **this ?? to 29**
*/
});
Run Code Online (Sandbox Code Playgroud)
Vin*_*zoC 10
如果您查看locale/ar-sa.js代码,您会注意到 moment 使用preparse和postformat从数字字符转换为阿拉伯语。
您可以简单地恢复默认行为重置preparse和postformat(例如查看时刻代码:function preParsePostFormat (string) { return string; })
这是一个实时示例:
console.log( moment().format() );
console.log( moment().format('dddd DD MMMM YYYY') );
moment.defineLocale('ar-sa-mine', {
parentLocale: 'ar-sa',
preparse: function (string) {
return string;
},
postformat: function (string) {
return string;
}
});
console.log( moment().format() );
console.log( moment().format('dddd DD MMMM YYYY') );Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.21.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.21.0/locale/ar-sa.js"></script>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1487 次 |
| 最近记录: |