Display numbers in English while localizing date with other language like Arabic or Hindi using Moment JS

Viewed 443

I want to localize date using moment js but show numbers in English only not any other language.

Suppose I have a date in hindi (hi).

नव. ३०, २०

I want to show this as

नव. 30, 20

I want this to also work in FromNow() , calendar() and humanize() functions too which provide the date in descriptive ways. for example)

कल दोपहर ११:१९ बजे

should be displayed as

कल दोपहर 11:19 बजे

1 Answers

you can customise it this way. added some comments but you can generally customise everything with regards to text the way you want it. ( set locale to 'en' to display normal numbers)

moment.locale('en', {
    // e.g months: "January_febuary_march_april......split('_')
    months : 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_'),
    monthsShort : 'janv._févr._mars_avr._mai_juin_juil._août_sept._oct._nov._déc.'.split('_'),
    monthsParseExact : true,
    weekdays : 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'.split('_'),
    weekdaysShort : 'dim._lun._mar._mer._jeu._ven._sam.'.split('_'),
    weekdaysMin : 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'),
    weekdaysParseExact : true,
    longDateFormat : {
        LT : 'HH:mm',
        LTS : 'HH:mm:ss',
        L : 'DD/MM/YYYY',
        LL : 'D MMMM YYYY',
        LLL : 'D MMMM YYYY HH:mm',
        LLLL : 'dddd D MMMM YYYY HH:mm'
    },
    calendar : {
        sameDay : '[Aujourd’hui à] LT',
        nextDay : '[Demain à] LT',
        nextWeek : 'dddd [à] LT',
        lastDay : '[Hier à] LT',
        lastWeek : 'dddd [dernier à] LT',
        sameElse : 'L'
    },
//the text in [] are generated as it is
    relativeTime : {
        future : 'dans %s', //in %s seconds
        past : 'il y a %s', // %s seconds ago
        s : 'quelques secondes', //a second
        m : 'une minute', //a minute
        mm : '%d minutes', 
        h : 'une heure', //an hour
        hh : '%d heures',
        d : 'un jour', //a day
        dd : '%d jours', //%d days
        M : 'un mois', //a month
        MM : '%d mois', //%d months
        y : 'un an',
        yy : '%d ans'
    },
    dayOfMonthOrdinalParse : /\d{1,2}(er|e)/,
    ordinal : function (number) {
        return number + (number === 1 ? 'er' : 'e');
    },
    meridiemParse : /PD|MD/,
    isPM : function (input) {
        return input.charAt(0) === 'M';
    },
    // In case the meridiem units are not separated around 12, then implement
    // this function (look at locale/id.js for an example).
    // meridiemHour : function (hour, meridiem) {
    //     return /* 0-23 hour, given meridiem token and hour 1-12 */ ;
    // },
    meridiem : function (hours, minutes, isLower) {
        return hours < 12 ? 'PD' : 'MD';
    },
    week : {
        dow : 1, // Monday is the first day of the week.
        doy : 4  // Used to determine first week of the year.
    }
});
Related