Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6059567
moment-locale-overrides.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
moment-locale-overrides.js
View Options
/* global moment */
(
function
()
{
// Define a locale if the current language doesn't have one, so that we can apply overrides
// without affecting the defaults for English (T313188)
if
(
moment
.
locale
()
===
'en'
&&
mw
.
config
.
get
(
'wgUserLanguage'
)
!==
'en'
)
{
moment
.
defineLocale
(
mw
.
config
.
get
(
'wgUserLanguage'
),
{
parentLocale
:
'en'
}
);
}
// HACK: Overwrite moment's i18n with MediaWiki's for the current language so that
// wgTranslateNumerals is respected.
moment
.
updateLocale
(
moment
.
locale
(),
{
preparse
:
function
(
s
)
{
const
table
=
mw
.
language
.
getDigitTransformTable
();
if
(
mw
.
config
.
get
(
'wgTranslateNumerals'
)
)
{
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
if
(
table
[
i
]
!==
undefined
)
{
s
=
s
.
replace
(
new
RegExp
(
mw
.
util
.
escapeRegExp
(
table
[
i
]
),
'g'
),
i
);
}
}
}
// HACK: momentjs replaces commas in some languages, which is the only other use of preparse
// aside from digit transformation. We can only override preparse, not extend it, so we
// have to replicate the comma replacement functionality here.
if
(
[
'ar'
,
'ar-sa'
,
'fa'
].
indexOf
(
mw
.
config
.
get
(
'wgUserLanguage'
)
)
!==
-
1
)
{
s
=
s
.
replace
(
/،/g
,
','
);
}
return
s
;
},
postformat
:
function
(
s
)
{
const
table
=
mw
.
language
.
getDigitTransformTable
();
if
(
mw
.
config
.
get
(
'wgTranslateNumerals'
)
)
{
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
if
(
table
[
i
]
!==
undefined
)
{
s
=
s
.
replace
(
new
RegExp
(
i
,
'g'
),
table
[
i
]
);
}
}
}
// HACK: momentjs replaces commas in some languages, which is the only other use of postformat
// aside from digit transformation. We can only override postformat, not extend it, so we
// have to replicate the comma replacement functionality here.
if
(
[
'ar'
,
'ar-sa'
,
'fa'
].
indexOf
(
mw
.
config
.
get
(
'wgUserLanguage'
)
)
!==
-
1
)
{
s
=
s
.
replace
(
/,/g
,
'،'
);
}
return
s
;
}
}
);
}()
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Oct 5 2026, 02:14 (8 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
2a/6f/e093f7ec87f0cdf214fbab8a6027
Default Alt Text
moment-locale-overrides.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment