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