Add language setting for time formatting.
This commit is contained in:
parent
6ba017d898
commit
fe86c44bf8
@ -493,7 +493,7 @@ Settings =
|
|||||||
$.id('lastarchivecheck').textContent = 'never'
|
$.id('lastarchivecheck').textContent = 'never'
|
||||||
|
|
||||||
items = {}
|
items = {}
|
||||||
for name in ['archiveLists', 'archiveAutoUpdate', 'captchaLanguage', 'boardnav', 'time', 'backlink', 'fileInfo', 'QR.personas', 'favicon', 'usercss', 'customCooldown', 'jsWhitelist']
|
for name in ['archiveLists', 'archiveAutoUpdate', 'captchaLanguage', 'boardnav', 'time', 'timeLocale', 'backlink', 'fileInfo', 'QR.personas', 'favicon', 'usercss', 'customCooldown', 'jsWhitelist']
|
||||||
items[name] = Conf[name]
|
items[name] = Conf[name]
|
||||||
input = inputs[name]
|
input = inputs[name]
|
||||||
event = if name in ['archiveLists', 'archiveAutoUpdate', 'QR.personas', 'favicon', 'usercss'] then 'change' else 'input'
|
event = if name in ['archiveLists', 'archiveAutoUpdate', 'QR.personas', 'favicon', 'usercss'] then 'change' else 'input'
|
||||||
@ -646,6 +646,9 @@ Settings =
|
|||||||
time: ->
|
time: ->
|
||||||
@nextElementSibling.textContent = Time.format @value, new Date()
|
@nextElementSibling.textContent = Time.format @value, new Date()
|
||||||
|
|
||||||
|
timeLocale: ->
|
||||||
|
Settings.time.call $('[name=time]', Settings.dialog)
|
||||||
|
|
||||||
backlink: ->
|
backlink: ->
|
||||||
@nextElementSibling.textContent = @value.replace /%(?:id|%)/g, (x) -> ({'%id': '123456789', '%%': '%'})[x]
|
@nextElementSibling.textContent = @value.replace /%(?:id|%)/g, (x) -> ({'%id': '123456789', '%%': '%'})[x]
|
||||||
|
|
||||||
|
|||||||
@ -64,6 +64,7 @@
|
|||||||
<div>Minute: <code>%M</code></div>
|
<div>Minute: <code>%M</code></div>
|
||||||
<div>Second: <code>%S</code></div>
|
<div>Second: <code>%S</code></div>
|
||||||
<div>Literal <code>%</code>: <code>%%</code></div>
|
<div>Literal <code>%</code>: <code>%%</code></div>
|
||||||
|
<div><a href="https://www.w3.org/International/articles/language-tags/" target="_blank">Language tag</a>: <input name="timeLocale" class="field" spellcheck="false"></div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|||||||
@ -41,13 +41,26 @@ Time =
|
|||||||
'December'
|
'December'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
localeFormat: (date, options, defaultValue) ->
|
||||||
|
if Conf['timeLocale']
|
||||||
|
try
|
||||||
|
return Intl.DateTimeFormat(Conf['timeLocale'], options).format(date)
|
||||||
|
defaultValue
|
||||||
|
|
||||||
|
localeFormatPart: (date, options, part, defaultValue) ->
|
||||||
|
if Conf['timeLocale']
|
||||||
|
try
|
||||||
|
parts = Intl.DateTimeFormat(Conf['timeLocale'], options).formatToParts(date)
|
||||||
|
return parts.map((x) -> if x.type is part then x.value else '').join('')
|
||||||
|
defaultValue
|
||||||
|
|
||||||
zeroPad: (n) -> if n < 10 then "0#{n}" else n
|
zeroPad: (n) -> if n < 10 then "0#{n}" else n
|
||||||
|
|
||||||
formatters:
|
formatters:
|
||||||
a: -> Time.day[@getDay()][...3]
|
a: -> Time.localeFormat @, {weekday: 'short'}, Time.day[@getDay()][...3]
|
||||||
A: -> Time.day[@getDay()]
|
A: -> Time.localeFormat @, {weekday: 'long'}, Time.day[@getDay()]
|
||||||
b: -> Time.month[@getMonth()][...3]
|
b: -> Time.localeFormat @, {month: 'short'}, Time.month[@getMonth()][...3]
|
||||||
B: -> Time.month[@getMonth()]
|
B: -> Time.localeFormat @, {month: 'long'}, Time.month[@getMonth()]
|
||||||
d: -> Time.zeroPad @getDate()
|
d: -> Time.zeroPad @getDate()
|
||||||
e: -> @getDate()
|
e: -> @getDate()
|
||||||
H: -> Time.zeroPad @getHours()
|
H: -> Time.zeroPad @getHours()
|
||||||
@ -56,8 +69,8 @@ Time =
|
|||||||
l: -> @getHours() % 12 or 12
|
l: -> @getHours() % 12 or 12
|
||||||
m: -> Time.zeroPad @getMonth() + 1
|
m: -> Time.zeroPad @getMonth() + 1
|
||||||
M: -> Time.zeroPad @getMinutes()
|
M: -> Time.zeroPad @getMinutes()
|
||||||
p: -> if @getHours() < 12 then 'AM' else 'PM'
|
p: -> Time.localeFormatPart @, {hour: 'numeric', hour12: true}, 'dayperiod', (if @getHours() < 12 then 'AM' else 'PM')
|
||||||
P: -> if @getHours() < 12 then 'am' else 'pm'
|
P: -> Time.formatters.p.call(@).toLowerCase()
|
||||||
S: -> Time.zeroPad @getSeconds()
|
S: -> Time.zeroPad @getSeconds()
|
||||||
y: -> @getFullYear().toString()[2..]
|
y: -> @getFullYear().toString()[2..]
|
||||||
Y: -> @getFullYear()
|
Y: -> @getFullYear()
|
||||||
|
|||||||
@ -857,6 +857,7 @@ Config =
|
|||||||
captchaLanguage: ''
|
captchaLanguage: ''
|
||||||
|
|
||||||
time: '%m/%d/%y(%a)%H:%M:%S'
|
time: '%m/%d/%y(%a)%H:%M:%S'
|
||||||
|
timeLocale: ''
|
||||||
|
|
||||||
backlink: '>>%id'
|
backlink: '>>%id'
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user