mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 06:37:18 +01:00
Added helper methods for locales.
This commit is contained in:
parent
ef616cc98d
commit
0a8c06b1f8
4 changed files with 18 additions and 10 deletions
|
|
@ -25,8 +25,7 @@ import {
|
|||
differenceInCalendarYears,
|
||||
format,
|
||||
} from 'date-fns';
|
||||
import { enUS } from 'date-fns/locale';
|
||||
import { languages } from 'lib/lang';
|
||||
import { getDateLocale } from 'lib/lang';
|
||||
|
||||
export function getTimezone() {
|
||||
return moment.tz.guess();
|
||||
|
|
@ -38,7 +37,7 @@ export function getLocalTime(t) {
|
|||
|
||||
export function getDateRange(value, locale = 'en-US') {
|
||||
const now = new Date();
|
||||
const dateLocale = languages[locale]?.dateLocale || enUS;
|
||||
const dateLocale = getDateLocale(locale);
|
||||
|
||||
const { num, unit } = value.match(/^(?<num>[0-9]+)(?<unit>hour|day|week|month|year)$/).groups;
|
||||
|
||||
|
|
@ -164,6 +163,6 @@ export const customFormats = {
|
|||
|
||||
export function dateFormat(date, str, locale = 'en-US') {
|
||||
return format(date, customFormats?.[locale]?.[str] || str, {
|
||||
locale: languages[locale]?.dateLocale || enUS,
|
||||
locale: getDateLocale(locale),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,3 +76,11 @@ export const languages = {
|
|||
'tr-TR': { label: 'Türkçe', dateLocale: tr },
|
||||
'uk-UA': { label: 'українська', dateLocale: uk },
|
||||
};
|
||||
|
||||
export function getDateLocale(locale) {
|
||||
return languages[locale]?.dateLocale || enUS;
|
||||
}
|
||||
|
||||
export function getTextDirection(locale) {
|
||||
return languages[locale]?.dir || 'ltr';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue