Add Chinese translation (Thank you copilot, and I swear I reviewed the code carefully)
This commit is contained in:
1 parent
77cdf19f7d
commit
e9d8a1c842
16 files changed
+324
-68
No files matched your search
@@ -3,6 +3,7 @@ import { getColor } from '@/util/color'
|
||||
import { Box, Tooltip, Modal } from '@mantine/core'
|
||||
import { useResizeObserver } from '@mantine/hooks'
|
||||
import { useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
const moment = require('moment')
|
||||
require('moment-precise-range-plugin')
|
||||
|
||||
@@ -13,6 +14,7 @@ export default function DetailBar({
|
||||
monitor: MonitorTarget
|
||||
state: MonitorState
|
||||
}) {
|
||||
const { t } = useTranslation('common')
|
||||
const [barRef, barRect] = useResizeObserver()
|
||||
const [modalOpened, setModalOpened] = useState(false)
|
||||
const [modalTitle, setModalTitle] = useState('')
|
||||
@@ -79,15 +81,21 @@ export default function DetailBar({
|
||||
events={{ hover: true, focus: false, touch: true }}
|
||||
label={
|
||||
Number.isNaN(Number(dayPercent)) ? (
|
||||
'No Data'
|
||||
t('No Data')
|
||||
) : (
|
||||
<>
|
||||
<div>{dayPercent + '% at ' + new Date(dayStart * 1000).toLocaleDateString()}</div>
|
||||
<div>
|
||||
{t('percent at date', {
|
||||
percent: dayPercent,
|
||||
date: new Date(dayStart * 1000).toLocaleDateString(),
|
||||
})}
|
||||
</div>
|
||||
{dayDownTime > 0 && (
|
||||
<div>{`Down for ${moment.preciseDiff(
|
||||
moment(0),
|
||||
moment(dayDownTime * 1000)
|
||||
)} (click for detail)`}</div>
|
||||
<div>
|
||||
{t('Down for', {
|
||||
duration: moment.preciseDiff(moment(0), moment(dayDownTime * 1000)),
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
@@ -105,7 +113,10 @@ export default function DetailBar({
|
||||
onClick={() => {
|
||||
if (dayDownTime > 0) {
|
||||
setModalTitle(
|
||||
`🚨 ${monitor.name} incidents at ${new Date(dayStart * 1000).toLocaleDateString()}`
|
||||
t('incidents at', {
|
||||
name: monitor.name,
|
||||
date: new Date(dayStart * 1000).toLocaleDateString(),
|
||||
})
|
||||
)
|
||||
setModelContent(
|
||||
<>
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import 'chartjs-adapter-moment'
|
||||
import { MonitorState, MonitorTarget } from '@/types/config'
|
||||
import { codeToCountry } from '@/util/iata'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
ChartJS.register(
|
||||
CategoryScale,
|
||||
@@ -32,6 +33,7 @@ export default function DetailChart({
|
||||
monitor: MonitorTarget
|
||||
state: MonitorState
|
||||
}) {
|
||||
const { t } = useTranslation('common')
|
||||
const latencyData = state.latency[monitor.id].recent.map((point) => ({
|
||||
x: point.time * 1000,
|
||||
y: point.ping,
|
||||
@@ -76,7 +78,7 @@ export default function DetailChart({
|
||||
},
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Response times(ms)',
|
||||
text: t('Response times'),
|
||||
align: 'start' as const,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,8 +2,10 @@ import { Container, Group, Image } from '@mantine/core'
|
||||
import classes from '@/styles/Header.module.css'
|
||||
import { pageConfig } from '@/uptime.config'
|
||||
import { PageConfigLink } from '@/types/config'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
export default function Header({ style }: { style?: React.CSSProperties }) {
|
||||
const { t } = useTranslation('common')
|
||||
const linkToElement = (link: PageConfigLink, i: number) => {
|
||||
return (
|
||||
<a
|
||||
@@ -18,7 +20,7 @@ export default function Header({ style }: { style?: React.CSSProperties }) {
|
||||
)
|
||||
}
|
||||
|
||||
const links = [{ label: 'Incidents', link: '/incidents' }, ...(pageConfig.links || [])]
|
||||
const links = [{ label: t('Incidents'), link: '/incidents' }, ...(pageConfig.links || [])]
|
||||
|
||||
return (
|
||||
<header className={classes.header} style={style}>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useMediaQuery } from '@mantine/hooks'
|
||||
import { IconAlertTriangle } from '@tabler/icons-react'
|
||||
import { MaintenanceConfig, MonitorTarget } from '@/types/config'
|
||||
import { pageConfig } from '@/uptime.config'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
export default function MaintenanceAlert({
|
||||
maintenance,
|
||||
@@ -13,6 +14,7 @@ export default function MaintenanceAlert({
|
||||
style?: React.CSSProperties
|
||||
upcoming?: boolean
|
||||
}) {
|
||||
const { t } = useTranslation('common')
|
||||
const theme = useMantineTheme()
|
||||
const isDesktop = useMediaQuery(`(min-width: ${theme.breakpoints.sm})`)
|
||||
|
||||
@@ -26,7 +28,7 @@ export default function MaintenanceAlert({
|
||||
fontWeight: 700,
|
||||
}}
|
||||
>
|
||||
{(upcoming ? '[Upcoming] ' : '') + (maintenance.title || 'Scheduled Maintenance')}
|
||||
{(upcoming ? t('Upcoming') : '') + (maintenance.title || t('Scheduled Maintenance'))}
|
||||
</span>
|
||||
}
|
||||
color={
|
||||
@@ -61,14 +63,14 @@ export default function MaintenanceAlert({
|
||||
}}
|
||||
>
|
||||
<div style={{ textAlign: 'right', fontWeight: 'bold' }}>
|
||||
{upcoming ? 'Scheduled for:' : 'From:'}
|
||||
{upcoming ? t('Scheduled for') : t('From')}
|
||||
</div>
|
||||
<div>{new Date(maintenance.start).toLocaleString()}</div>
|
||||
<div style={{ textAlign: 'right', fontWeight: 'bold' }}>
|
||||
{upcoming ? 'Expected end:' : 'To:'}
|
||||
{upcoming ? t('Expected end') : t('To')}
|
||||
</div>
|
||||
<div>
|
||||
{maintenance.end ? new Date(maintenance.end).toLocaleString() : 'Until further notice'}
|
||||
{maintenance.end ? new Date(maintenance.end).toLocaleString() : t('Until further notice')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -77,11 +79,11 @@ export default function MaintenanceAlert({
|
||||
{maintenance.monitors && maintenance.monitors.length > 0 && (
|
||||
<>
|
||||
<Text mt="xs">
|
||||
<b>Affected components:</b>
|
||||
<b>{t('Affected components')}</b>
|
||||
</Text>
|
||||
<List size="sm" withPadding>
|
||||
{maintenance.monitors.map((comp, compIdx) => (
|
||||
<List.Item key={compIdx}>{comp?.name ?? '[ERR: MONITOR ID NOT FOUND]'}</List.Item>
|
||||
<List.Item key={compIdx}>{comp?.name ?? t('MONITOR ID NOT FOUND')}</List.Item>
|
||||
))}
|
||||
</List>
|
||||
</>
|
||||
|
||||
@@ -5,6 +5,7 @@ import DetailChart from './DetailChart'
|
||||
import DetailBar from './DetailBar'
|
||||
import { getColor } from '@/util/color'
|
||||
import { maintenances } from '@/uptime.config'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
export default function MonitorDetail({
|
||||
monitor,
|
||||
@@ -13,6 +14,8 @@ export default function MonitorDetail({
|
||||
monitor: MonitorTarget
|
||||
state: MonitorState
|
||||
}) {
|
||||
const { t } = useTranslation('common')
|
||||
|
||||
if (!state.latency[monitor.id])
|
||||
return (
|
||||
<>
|
||||
@@ -20,8 +23,7 @@ export default function MonitorDetail({
|
||||
{monitor.name}
|
||||
</Text>
|
||||
<Text mt="sm" fw={700}>
|
||||
No data available, please make sure you have deployed your workers with latest config and
|
||||
check your worker status!
|
||||
{t('No data available')}
|
||||
</Text>
|
||||
</>
|
||||
)
|
||||
@@ -91,7 +93,7 @@ export default function MonitorDetail({
|
||||
)}
|
||||
|
||||
<Text mt="sm" fw={700} style={{ display: 'inline', color: getColor(uptimePercent, true) }}>
|
||||
Overall: {uptimePercent}%
|
||||
{t('Overall', { percent: uptimePercent })}
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Accordion, Card, Center, Text } from '@mantine/core'
|
||||
import MonitorDetail from './MonitorDetail'
|
||||
import { pageConfig } from '@/uptime.config'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
function countDownCount(state: MonitorState, ids: string[]) {
|
||||
let downCount = 0
|
||||
@@ -36,6 +37,7 @@ export default function MonitorList({
|
||||
monitors: MonitorTarget[]
|
||||
state: MonitorState
|
||||
}) {
|
||||
const { t } = useTranslation('common')
|
||||
const group = pageConfig.group
|
||||
const groupedMonitor = group && Object.keys(group).length > 0
|
||||
let content
|
||||
@@ -81,7 +83,7 @@ export default function MonitorList({
|
||||
}}
|
||||
>
|
||||
{group[groupName].length - countDownCount(state, group[groupName])}/
|
||||
{group[groupName].length} Operational
|
||||
{group[groupName].length} {t('Operational')}
|
||||
</Text>
|
||||
</div>
|
||||
</Accordion.Control>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Alert, Text } from '@mantine/core'
|
||||
import { IconInfoCircle } from '@tabler/icons-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
export default function NoIncidentsAlert({ style }: { style?: React.CSSProperties }) {
|
||||
const { t } = useTranslation('common')
|
||||
return (
|
||||
<Alert
|
||||
icon={<IconInfoCircle />}
|
||||
@@ -12,7 +14,7 @@ export default function NoIncidentsAlert({ style }: { style?: React.CSSPropertie
|
||||
fontWeight: 700,
|
||||
}}
|
||||
>
|
||||
{'No incidents in this month'}
|
||||
{t('No incidents in this month')}
|
||||
</span>
|
||||
}
|
||||
color="gray"
|
||||
@@ -23,7 +25,7 @@ export default function NoIncidentsAlert({ style }: { style?: React.CSSPropertie
|
||||
...style,
|
||||
}}
|
||||
>
|
||||
<Text>There are no incidents for this month.</Text>
|
||||
<Text>{t('There are no incidents for this month')}</Text>
|
||||
</Alert>
|
||||
)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { IconCircleCheck, IconAlertCircle, IconPlus, IconMinus } from '@tabler/i
|
||||
import { useEffect, useState } from 'react'
|
||||
import MaintenanceAlert from './MaintenanceAlert'
|
||||
import { pageConfig } from '@/uptime.config'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
function useWindowVisibility() {
|
||||
const [isVisible, setIsVisible] = useState(true)
|
||||
@@ -24,22 +25,24 @@ export default function OverallStatus({
|
||||
maintenances: MaintenanceConfig[]
|
||||
monitors: MonitorTarget[]
|
||||
}) {
|
||||
const { t } = useTranslation('common')
|
||||
let group = pageConfig.group
|
||||
let groupedMonitor = (group && Object.keys(group).length > 0) || false
|
||||
|
||||
let statusString = ''
|
||||
let icon = <IconAlertCircle style={{ width: 64, height: 64, color: '#b91c1c' }} />
|
||||
if (state.overallUp === 0 && state.overallDown === 0) {
|
||||
statusString = 'No data yet'
|
||||
statusString = t('No data yet')
|
||||
} else if (state.overallUp === 0) {
|
||||
statusString = 'All systems not operational'
|
||||
statusString = t('All systems not operational')
|
||||
} else if (state.overallDown === 0) {
|
||||
statusString = 'All systems operational'
|
||||
statusString = t('All systems operational')
|
||||
icon = <IconCircleCheck style={{ width: 64, height: 64, color: '#059669' }} />
|
||||
} else {
|
||||
statusString = `Some systems not operational (${state.overallDown} out of ${
|
||||
state.overallUp + state.overallDown
|
||||
})`
|
||||
statusString = t('Some systems not operational', {
|
||||
down: state.overallDown,
|
||||
total: state.overallUp + state.overallDown,
|
||||
})
|
||||
}
|
||||
|
||||
const [openTime] = useState(Math.round(Date.now() / 1000))
|
||||
@@ -89,24 +92,22 @@ export default function OverallStatus({
|
||||
{statusString}
|
||||
</Title>
|
||||
<Title mt="sm" style={{ textAlign: 'center', color: '#70778c' }} order={5}>
|
||||
Last updated on:{' '}
|
||||
{`${new Date(state.lastUpdate * 1000).toLocaleString()} (${
|
||||
currentTime - state.lastUpdate
|
||||
} sec ago)`}
|
||||
{t('Last updated on', {
|
||||
date: new Date(state.lastUpdate * 1000).toLocaleString(),
|
||||
seconds: currentTime - state.lastUpdate,
|
||||
})}
|
||||
</Title>
|
||||
|
||||
{/* Upcoming Maintenance */}
|
||||
{upcomingMaintenances.length > 0 && (
|
||||
<>
|
||||
<Title mt="4px" style={{ textAlign: 'center', color: '#70778c' }} order={5}>
|
||||
{`${upcomingMaintenances.length} upcoming ${
|
||||
upcomingMaintenances.length === 1 ? 'maintenance' : 'maintenances'
|
||||
}`}{' '}
|
||||
{t('upcoming maintenance', { count: upcomingMaintenances.length })}{' '}
|
||||
<span
|
||||
style={{ textDecoration: 'underline', cursor: 'pointer' }}
|
||||
onClick={() => setExpandUpcoming(!expandUpcoming)}
|
||||
>
|
||||
{expandUpcoming ? '[Hide]' : '[Show]'}
|
||||
{expandUpcoming ? t('Hide') : t('Show')}
|
||||
</span>
|
||||
</Title>
|
||||
|
||||
|
||||
Reference in new issue
Block a user