1 /* global moment, mw */
3 // HACK: Overwrite moment's i18n with MediaWiki's for the current language so that
4 // wgTranslateNumerals is respected.
5 moment.updateLocale( moment.locale(), {
6 preparse: function ( s ) {
8 table = mw.language.getDigitTransformTable();
9 if ( mw.config.get( 'wgTranslateNumerals' ) ) {
10 for ( i = 0; i < 10; i++ ) {
11 if ( table[ i ] !== undefined ) {
12 s = s.replace( new RegExp( mw.RegExp.escape( table[ i ] ), 'g' ), i );
16 // HACK: momentjs replaces commas in some languages, which is the only other use of preparse
17 // aside from digit transformation. We can only override preparse, not extend it, so we
18 // have to replicate the comma replacement functionality here.
19 if ( [ 'ar', 'ar-sa', 'fa' ].indexOf( mw.config.get( 'wgUserLanguage' ) ) !== -1 ) {
20 s = s.replace( /،/g, ',' );
24 postformat: function ( s ) {
26 table = mw.language.getDigitTransformTable();
27 if ( mw.config.get( 'wgTranslateNumerals' ) ) {
28 for ( i = 0; i < 10; i++ ) {
29 if ( table[ i ] !== undefined ) {
30 s = s.replace( new RegExp( i, 'g' ), table[ i ] );
34 // HACK: momentjs replaces commas in some languages, which is the only other use of postformat
35 // aside from digit transformation. We can only override postformat, not extend it, so we
36 // have to replicate the comma replacement functionality here.
37 if ( [ 'ar', 'ar-sa', 'fa' ].indexOf( mw.config.get( 'wgUserLanguage' ) ) !== -1 ) {
38 s = s.replace( /,/g, '،' );