mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 15:23:38 +01:00
Add timestamp localization
This commit is contained in:
parent
30ebf7b266
commit
e7b92cd097
@ -3,7 +3,7 @@ import classNames from 'classnames';
|
|||||||
import ChartJS from 'chart.js';
|
import ChartJS from 'chart.js';
|
||||||
import Legend from 'components/metrics/Legend';
|
import Legend from 'components/metrics/Legend';
|
||||||
import { formatLongNumber } from 'lib/format';
|
import { formatLongNumber } from 'lib/format';
|
||||||
import { dateFormat } from 'lib/lang';
|
import { dateFormat, timeFormat } from 'lib/lang';
|
||||||
import useLocale from 'hooks/useLocale';
|
import useLocale from 'hooks/useLocale';
|
||||||
import useTheme from 'hooks/useTheme';
|
import useTheme from 'hooks/useTheme';
|
||||||
import { DEFAUL_CHART_HEIGHT, DEFAULT_ANIMATION_DURATION, THEME_COLORS } from 'lib/constants';
|
import { DEFAUL_CHART_HEIGHT, DEFAULT_ANIMATION_DURATION, THEME_COLORS } from 'lib/constants';
|
||||||
@ -46,7 +46,7 @@ export default function BarChart({
|
|||||||
case 'minute':
|
case 'minute':
|
||||||
return index % 2 === 0 ? dateFormat(d, 'h:mm', locale) : '';
|
return index % 2 === 0 ? dateFormat(d, 'h:mm', locale) : '';
|
||||||
case 'hour':
|
case 'hour':
|
||||||
return dateFormat(d, 'ha', locale);
|
return timeFormat(d, locale);
|
||||||
case 'day':
|
case 'day':
|
||||||
if (records > 31) {
|
if (records > 31) {
|
||||||
if (w <= 500) {
|
if (w <= 500) {
|
||||||
@ -131,6 +131,7 @@ export default function BarChart({
|
|||||||
minRotation: 0,
|
minRotation: 0,
|
||||||
maxRotation: 0,
|
maxRotation: 0,
|
||||||
fontColor: colors.text,
|
fontColor: colors.text,
|
||||||
|
autoSkipPadding: 1,
|
||||||
},
|
},
|
||||||
gridLines: {
|
gridLines: {
|
||||||
display: false,
|
display: false,
|
||||||
|
@ -118,6 +118,11 @@ export const dateLocales = {
|
|||||||
'it-IT': it,
|
'it-IT': it,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const timeFormats = {
|
||||||
|
// https://date-fns.org/v2.17.0/docs/format
|
||||||
|
'en-US': 'ha',
|
||||||
|
};
|
||||||
|
|
||||||
export const menuOptions = [
|
export const menuOptions = [
|
||||||
{ label: '中文', value: 'zh-CN', display: 'cn' },
|
{ label: '中文', value: 'zh-CN', display: 'cn' },
|
||||||
{ label: '中文(繁體)', value: 'zh-TW', display: 'tw' },
|
{ label: '中文(繁體)', value: 'zh-TW', display: 'tw' },
|
||||||
@ -152,3 +157,7 @@ export const menuOptions = [
|
|||||||
export function dateFormat(date, str, locale) {
|
export function dateFormat(date, str, locale) {
|
||||||
return format(date, str, { locale: dateLocales[locale] || enUS });
|
return format(date, str, { locale: dateLocales[locale] || enUS });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function timeFormat(date, locale = 'en-US') {
|
||||||
|
return format(date, timeFormats[locale] || 'p', { locale: dateLocales[locale] });
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user