I want to create my own locale in moment.js, its parent should be the Arabic local but I want only to change to numeric format to display 0-9
, not the default display.
As per documentation, I can start with that:
moment.defineLocale('ar-sa-mine', {
parentLocale: 'ar-sa',
/*
here I need to specify the numeric: change **this ٢٩ to 29**
*/
});
If you look at locale/ar-sa.js
code you will note that moment uses preparse
and postformat
to convert from numeric characters to arabic.
You can simply restore default behaviour resetting preparse
and postformat
(e.g. see moment code: function preParsePostFormat (string) { return string; }
)
Here a live sample:
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') );
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With