Add language setting for time formatting.
This commit is contained in:
parent
6ba017d898
commit
fe86c44bf8
@ -493,7 +493,7 @@ Settings =
|
||||
$.id('lastarchivecheck').textContent = 'never'
|
||||
|
||||
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]
|
||||
input = inputs[name]
|
||||
event = if name in ['archiveLists', 'archiveAutoUpdate', 'QR.personas', 'favicon', 'usercss'] then 'change' else 'input'
|
||||
@ -646,6 +646,9 @@ Settings =
|
||||
time: ->
|
||||
@nextElementSibling.textContent = Time.format @value, new Date()
|
||||
|
||||
timeLocale: ->
|
||||
Settings.time.call $('[name=time]', Settings.dialog)
|
||||
|
||||
backlink: ->
|
||||
@nextElementSibling.textContent = @value.replace /%(?:id|%)/g, (x) -> ({'%id': '123456789', '%%': '%'})[x]
|
||||
|
||||
|
||||
@ -64,6 +64,7 @@
|
||||
<div>Minute: <code>%M</code></div>
|
||||
<div>Second: <code>%S</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>
|
||||
|
||||
@ -41,13 +41,26 @@ Time =
|
||||
'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
|
||||
|
||||
formatters:
|
||||
a: -> Time.day[@getDay()][...3]
|
||||
A: -> Time.day[@getDay()]
|
||||
b: -> Time.month[@getMonth()][...3]
|
||||
B: -> Time.month[@getMonth()]
|
||||
a: -> Time.localeFormat @, {weekday: 'short'}, Time.day[@getDay()][...3]
|
||||
A: -> Time.localeFormat @, {weekday: 'long'}, Time.day[@getDay()]
|
||||
b: -> Time.localeFormat @, {month: 'short'}, Time.month[@getMonth()][...3]
|
||||
B: -> Time.localeFormat @, {month: 'long'}, Time.month[@getMonth()]
|
||||
d: -> Time.zeroPad @getDate()
|
||||
e: -> @getDate()
|
||||
H: -> Time.zeroPad @getHours()
|
||||
@ -56,8 +69,8 @@ Time =
|
||||
l: -> @getHours() % 12 or 12
|
||||
m: -> Time.zeroPad @getMonth() + 1
|
||||
M: -> Time.zeroPad @getMinutes()
|
||||
p: -> if @getHours() < 12 then 'AM' else 'PM'
|
||||
P: -> if @getHours() < 12 then 'am' else 'pm'
|
||||
p: -> Time.localeFormatPart @, {hour: 'numeric', hour12: true}, 'dayperiod', (if @getHours() < 12 then 'AM' else 'PM')
|
||||
P: -> Time.formatters.p.call(@).toLowerCase()
|
||||
S: -> Time.zeroPad @getSeconds()
|
||||
y: -> @getFullYear().toString()[2..]
|
||||
Y: -> @getFullYear()
|
||||
|
||||
@ -857,6 +857,7 @@ Config =
|
||||
captchaLanguage: ''
|
||||
|
||||
time: '%m/%d/%y(%a)%H:%M:%S'
|
||||
timeLocale: ''
|
||||
|
||||
backlink: '>>%id'
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user