1
0

Add translations (#562)

Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/562
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-committed-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad
2021-06-23 23:24:57 +00:00
parent 5badb65037
commit f0498fd767
103 changed files with 2306 additions and 973 deletions

View File

@ -0,0 +1,40 @@
import {createDateFromString} from '@/helpers/time/createDateFromString'
import {format, formatDistance} from 'date-fns'
import { enGB, de } from 'date-fns/locale'
const locales = {enGB, de}
const dateIsValid = date => {
if (date === null) {
return false
}
return date instanceof Date && !isNaN(date)
}
export const formatDate = (date, f, locale) => {
if (!dateIsValid(date)) {
return ''
}
date = createDateFromString(date)
return date ? format(date, f, {locale: locales[locale]}) : ''
}
export const formatDateSince = (date, $t) => {
if (!dateIsValid(date)) {
return ''
}
date = createDateFromString(date)
const currentDate = new Date()
const distance = formatDistance(date, currentDate)
if (date > currentDate) {
return $t('date.in', {date: distance})
}
return $t('date.ago', {date: distance})
}