summaryrefslogtreecommitdiff
path: root/src/components/ConnectionTable.tsx
diff options
context:
space:
mode:
authoryaling888 <[email protected]>2022-05-17 03:59:22 +0800
committeryaling888 <[email protected]>2022-05-17 03:59:22 +0800
commit116f7fe71a4a85222fcb677c91be0db70891bc10 (patch)
tree46bb1e33ed019126776fbd11c6b31074fdb6e1b2 /src/components/ConnectionTable.tsx
parent70805df1a590b70b0eaf1f1653f9d6b3efecf75c (diff)
feat: add i18n to connections page
Diffstat (limited to 'src/components/ConnectionTable.tsx')
-rw-r--r--src/components/ConnectionTable.tsx40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/components/ConnectionTable.tsx b/src/components/ConnectionTable.tsx
index f2e70a4..a8ad827 100644
--- a/src/components/ConnectionTable.tsx
+++ b/src/components/ConnectionTable.tsx
@@ -1,7 +1,9 @@
import cx from 'clsx';
-import { formatDistance } from 'date-fns';
+import { formatDistance, Locale } from 'date-fns';
+import { enUS, zhCN } from 'date-fns/locale'
import React from 'react';
import { ChevronDown } from 'react-feather';
+import { useTranslation } from 'react-i18next';
import { useSortBy, useTable } from 'react-table';
import prettyBytes from '../misc/pretty-bytes';
@@ -11,24 +13,24 @@ const sortDescFirst = true;
const columns = [
{ accessor: 'id', show: false },
- { Header: 'Host', accessor: 'host' },
- { Header: 'Process', accessor: 'process' },
- { Header: 'DL', accessor: 'download', sortDescFirst },
- { Header: 'UL', accessor: 'upload', sortDescFirst },
- { Header: 'DL Speed', accessor: 'downloadSpeedCurr', sortDescFirst },
- { Header: 'UL Speed', accessor: 'uploadSpeedCurr', sortDescFirst },
- { Header: 'Chains', accessor: 'chains' },
- { Header: 'Rule', accessor: 'rule' },
- { Header: 'Time', accessor: 'start', sortDescFirst },
- { Header: 'Source', accessor: 'source' },
- { Header: 'Destination IP', accessor: 'destinationIP' },
- { Header: 'Type', accessor: 'type' },
+ { Header: 'c_host', accessor: 'host' },
+ { Header: 'c_process', accessor: 'process' },
+ { Header: 'c_dl', accessor: 'download', sortDescFirst },
+ { Header: 'c_ul', accessor: 'upload', sortDescFirst },
+ { Header: 'c_dl_speed', accessor: 'downloadSpeedCurr', sortDescFirst },
+ { Header: 'c_ul_speed', accessor: 'uploadSpeedCurr', sortDescFirst },
+ { Header: 'c_chains', accessor: 'chains' },
+ { Header: 'c_rule', accessor: 'rule' },
+ { Header: 'c_time', accessor: 'start', sortDescFirst },
+ { Header: 'c_source', accessor: 'source' },
+ { Header: 'c_destination_ip', accessor: 'destinationIP' },
+ { Header: 'c_type', accessor: 'type' },
];
-function renderCell(cell: { column: { id: string }; value: number }) {
+function renderCell(cell: { column: { id: string }; value: number }, locale: Locale) {
switch (cell.column.id) {
case 'start':
- return formatDistance(cell.value, 0);
+ return formatDistance(cell.value, 0, { locale: locale });
case 'download':
case 'upload':
return prettyBytes(cell.value);
@@ -59,6 +61,10 @@ function Table({ data }) {
},
useSortBy
);
+
+ const { t, i18n } = useTranslation();
+ const locale = i18n.language === 'zh' ? zhCN : enUS;
+
return (
<div {...getTableProps()}>
{headerGroups.map((headerGroup) => {
@@ -69,7 +75,7 @@ function Table({ data }) {
{...column.getHeaderProps(column.getSortByToggleProps())}
className={s.th}
>
- <span>{column.render('Header')}</span>
+ <span>{t(column.render('Header'))}</span>
<span className={s.sortIconContainer}>
{column.isSorted ? (
<span className={column.isSortedDesc ? '' : s.rotate180}>
@@ -92,7 +98,7 @@ function Table({ data }) {
j >= 2 && j <= 5 ? s.du : false
)}
>
- {renderCell(cell)}
+ {renderCell(cell, locale)}
</div>
);
});