Merge "Remove DELETE_SOURCE flag from FileRepo store()/storeBatch()"
[lhc/web/wiklou.git] / resources / src / moment-locale-overrides.js
1 // Use DMY date format for Moment.js, in accordance with MediaWiki's date formatting routines.
2 // This affects English only (and languages without localisations, that fall back to English).
3 // http://momentjs.com/docs/#/customization/long-date-formats/
4 /*global moment, mw */
5 moment.locale( 'en', {
6 longDateFormat: {
7 // Unchanged, but have to be repeated here:
8 LT: 'h:mm A',
9 LTS: 'h:mm:ss A',
10 // Customized:
11 L: 'DD/MM/YYYY',
12 LL: 'D MMMM YYYY',
13 LLL: 'D MMMM YYYY LT',
14 LLLL: 'dddd, D MMMM YYYY LT'
15 }
16 } );
17
18 // HACK: Overwrite moment's i18n with MediaWiki's for the current language so that
19 // wgTranslateNumerals is respected.
20 moment.locale( moment.locale(), {
21 preparse: function ( s ) {
22 var i,
23 table = mw.language.getDigitTransformTable();
24 if ( mw.config.get( 'wgTranslateNumerals' ) ) {
25 for ( i = 0; i < 10; i++ ) {
26 if ( table[ i ] !== undefined ) {
27 s = s.replace( new RegExp( mw.RegExp.escape( table[ i ] ), 'g' ), i );
28 }
29 }
30 }
31 // HACK: momentjs replaces commas in some languages, which is the only other use of preparse
32 // aside from digit transformation. We can only override preparse, not extend it, so we
33 // have to replicate the comma replacement functionality here.
34 if ( [ 'ar', 'ar-sa', 'fa' ].indexOf( mw.config.get( 'wgUserLanguage' ) ) !== -1 ) {
35 s = s.replace( /،/g, ',' );
36 }
37 return s;
38 },
39 postformat: function ( s ) {
40 var i,
41 table = mw.language.getDigitTransformTable();
42 if ( mw.config.get( 'wgTranslateNumerals' ) ) {
43 for ( i = 0; i < 10; i++ ) {
44 if ( table[ i ] !== undefined ) {
45 s = s.replace( new RegExp( mw.RegExp.escape( i ), 'g' ), table[ i ] );
46 }
47 }
48 }
49 // HACK: momentjs replaces commas in some languages, which is the only other use of postformat
50 // aside from digit transformation. We can only override postformat, not extend it, so we
51 // have to replicate the comma replacement functionality here.
52 if ( [ 'ar', 'ar-sa', 'fa' ].indexOf( mw.config.get( 'wgUserLanguage' ) ) !== -1 ) {
53 s = s.replace( /,/g, '،' );
54 }
55 return s;
56 }
57 } );