mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-01-01 00:29:38 +00:00
localized date-fns library
This commit is contained in:
parent
030c20b12e
commit
e8d582269b
10 changed files with 27 additions and 1 deletions
|
|
@ -73,6 +73,8 @@ async function loadi18n(code) {
|
|||
for (const key in Vue.prototype.$strings) {
|
||||
Vue.prototype.$strings[key] = strings[key] || translations[defaultCode][key]
|
||||
}
|
||||
console.log(`ConfigDateFnsLocale = ${translations[code].ConfigDateFnsLocale}`)
|
||||
Vue.prototype.$setDateFnsLocale(translations[code].ConfigDateFnsLocale)
|
||||
|
||||
console.log('i18n strings=', Vue.prototype.$strings)
|
||||
Vue.prototype.$eventBus.$emit('change-lang', code)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,26 @@
|
|||
import Vue from 'vue'
|
||||
import Path from 'path'
|
||||
import vClickOutside from 'v-click-outside'
|
||||
import { formatDistance, format, addDays, isDate } from 'date-fns'
|
||||
import { formatDistance, format, addDays, isDate, setDefaultOptions } from 'date-fns'
|
||||
import { de as localeDE, enUS as localeENUS, es as localeES, fr as localeFR, hr as localeHR, it as localeIT, pl as localePL, zhCN as localeZNCN } from 'date-fns/locale'
|
||||
let locale = {
|
||||
de: localeDE,
|
||||
enUS: localeENUS,
|
||||
es: localeES,
|
||||
fr: localeFR,
|
||||
hr: localeHR,
|
||||
it: localeIT,
|
||||
pl: localePL,
|
||||
znCN: localeZNCN
|
||||
}
|
||||
|
||||
Vue.directive('click-outside', vClickOutside.directive)
|
||||
|
||||
|
||||
Vue.prototype.$setDateFnsLocale = (localeString) => {
|
||||
if (!locale[localeString]) return 0
|
||||
return setDefaultOptions({locale: locale[localeString]})
|
||||
}
|
||||
Vue.prototype.$dateDistanceFromNow = (unixms) => {
|
||||
if (!unixms) return ''
|
||||
return formatDistance(unixms, Date.now(), { addSuffix: true })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue