Solía convertir números arábigos a números latinos haciendo lo siguiente
moment.updateLocale('ar', <MomentLanguage>{
preparse: (str) => {
return str.replace(/\u200f/g, '');
},
postformat: (str) => {
return str;
}
});
pero ahora, MomentLanguage no es un módulo en moment, ¿qué debo hacer?
PD: estoy usando la versión 2.15.2
Su código está escrito con Typescript, ¿verdad? Creo que la interfaz que estás usando ahora se llama Locale
.
Cerrando ya que no hemos tenido noticias desde el comentario de Lucas. Vuelva a abrir si aún necesita ayuda.
@IbraheemAlSaady esto debería funcionar
const symbolMap = {
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',
'6': '6',
'7': '7',
'8': '8',
'9': '9',
'0': '0'
};
const numberMap = {
'١': '1',
'٢': '2',
'٣': '3',
'٤': '4',
'٥': '5',
'٦': '6',
'٧': '7',
'٨': '8',
'٩': '9',
'٠': '0'
}
moment.updateLocale('ar', {
preparse: function (string) {
return string.replace(/\u200f/g, '').replace(/[١٢٣٤٥٦٧٨٩٠]/g, function (match) {
return numberMap[match];
}).replace(/،/g, ',');
},
postformat: function(string) {
return string.replace(/\d/g, function(match) {
return symbolMap[match];
}).replace(/,/g, '،');
},
});
Comentario más útil
@IbraheemAlSaady esto debería funcionar