umami/components/metrics/LanguagesTable.js

28 lines
861 B
JavaScript
Raw Normal View History

2021-12-02 04:32:45 +01:00
import MetricsTable from './MetricsTable';
import { percentFilter } from 'lib/filters';
import useLanguageNames from 'hooks/useLanguageNames';
import useLocale from 'hooks/useLocale';
2023-03-31 14:55:28 +02:00
import useMessages from 'hooks/useMessages';
2021-12-02 04:32:45 +01:00
export default function LanguagesTable({ websiteId, onDataLoad, ...props }) {
2023-03-31 14:55:28 +02:00
const { formatMessage, labels } = useMessages();
2021-12-02 04:32:45 +01:00
const { locale } = useLocale();
const languageNames = useLanguageNames(locale);
2023-03-31 14:55:28 +02:00
const renderLabel = ({ x }) => {
return <div className={locale}>{languageNames[x?.split('-')[0]] ?? x}</div>;
};
2021-12-02 04:32:45 +01:00
return (
<MetricsTable
{...props}
2023-03-31 14:55:28 +02:00
title={formatMessage(labels.languages)}
2021-12-02 04:32:45 +01:00
type="language"
2023-03-31 14:55:28 +02:00
metric={formatMessage(labels.visitors)}
2021-12-02 04:32:45 +01:00
websiteId={websiteId}
onDataLoad={data => onDataLoad?.(percentFilter(data))}
renderLabel={renderLabel}
/>
);
}