4 // Define a locale if the current language doesn't have one, so that we can apply overrides
5 // without affecting the defaults for English (T313188)
6 if ( moment.locale() === 'en' && mw.config.get( 'wgUserLanguage' ) !== 'en' ) {
7 moment.defineLocale( mw.config.get( 'wgUserLanguage' ), {
12 // HACK: Overwrite moment's i18n with MediaWiki's for the current language so that
13 // wgTranslateNumerals is respected.
14 moment.updateLocale( moment.locale(), {
15 preparse: function ( s ) {
16 const table = mw.language.getDigitTransformTable();
17 if ( mw.config.get( 'wgTranslateNumerals' ) ) {
18 for ( let i = 0; i < 10; i++ ) {
19 if ( table[ i ] !== undefined ) {
21 s = s.replace( new RegExp( mw.util.escapeRegExp( table[ i ] ), 'g' ), i );
25 // HACK: momentjs replaces commas in some languages, which is the only other use of preparse
26 // aside from digit transformation. We can only override preparse, not extend it, so we
27 // have to replicate the comma replacement functionality here.
28 if ( [ 'ar', 'ar-sa', 'fa' ].indexOf( mw.config.get( 'wgUserLanguage' ) ) !== -1 ) {
29 s = s.replace( /،/g, ',' );
33 postformat: function ( s ) {
34 const table = mw.language.getDigitTransformTable();
35 if ( mw.config.get( 'wgTranslateNumerals' ) ) {
36 for ( let i = 0; i < 10; i++ ) {
37 if ( table[ i ] !== undefined ) {
39 s = s.replace( new RegExp( i, 'g' ), table[ i ] );
43 // HACK: momentjs replaces commas in some languages, which is the only other use of postformat
44 // aside from digit transformation. We can only override postformat, not extend it, so we
45 // have to replicate the comma replacement functionality here.
46 if ( [ 'ar', 'ar-sa', 'fa' ].indexOf( mw.config.get( 'wgUserLanguage' ) ) !== -1 ) {
47 s = s.replace( /,/g, '،' );