Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/i18n/resources/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
"NETWORK ID": "网络 ID",
"NAME": "名称",
"STATUS": "状态",
"Ethernet": "以太网",
"Device": "设备",
"Type": "类型",
"Allow Managed Addresses": "允许托管地址",
"Allow Assignment of Global IPs": "允许分配全局 IP",
"Allow Default Router Override": "允许覆盖默认路由",
"Allow DNS Configuration": "允许 DNS 配置",
"Managed Addresses": "托管地址",
"Managed Routes": "托管路由",
"{{target}} via {{device}}": "{{target}} 经由 {{device}}",
"Refresh": "刷新",
"Join New": "加入网络",
"Search by Network ID...": "搜索网络 ID...",
Expand Down
49 changes: 36 additions & 13 deletions src/pages/Zerotier/Networks/NetworkDetailsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Checkbox, CheckboxGroup, Divider, Modal, ModalBody, ModalContent, ModalProps } from '@heroui/react'
import classNames from 'classnames'
import { useEffect, useState } from 'react'
import { Trans } from 'react-i18next'

import CopyText from '../../../components/base/CopyText.tsx'
import { updateNetwork } from '../../../services/zerotierService.ts'
Expand Down Expand Up @@ -55,35 +56,47 @@ function NetworkDetailsModal({
<div className="w-full flex space-x-2 py-6">
<div className="w-full flex flex-col gap-3">
<div className="flex flex-col gap-0.5">
<p className="text-tiny font-bold uppercase">Network ID</p>
<p className="text-tiny font-bold uppercase">
<Trans>NETWORK ID</Trans>
</p>
<CopyText copyValue={networkDetails?.id}>
<small className="text-default-500">{networkDetails?.id}</small>
</CopyText>
</div>
<div className={classNames('flex flex-col gap-0.5', !networkDetails?.name && 'hidden')}>
<p className="text-tiny font-bold uppercase">Name</p>
<p className="text-tiny font-bold uppercase">
<Trans>NAME</Trans>
</p>
<CopyText copyValue={networkDetails?.name}>
<small className="text-default-500">{networkDetails?.name}</small>
</CopyText>
</div>
<div className="flex flex-col gap-0.5">
<p className="text-tiny font-bold uppercase">Status</p>
<p className="text-tiny font-bold uppercase">
<Trans>STATUS</Trans>
</p>
<small className="text-default-500">{networkDetails?.status}</small>
</div>
<div className="flex flex-col gap-0.5">
<p className="text-tiny font-bold uppercase">Ethernet</p>
<p className="text-tiny font-bold uppercase">
<Trans>Ethernet</Trans>
</p>
<CopyText copyValue={networkDetails?.mac}>
<small className="text-default-500">{networkDetails?.mac}</small>
</CopyText>
</div>
<div className="flex flex-col gap-0.5">
<p className="text-tiny font-bold uppercase">Device</p>
<p className="text-tiny font-bold uppercase">
<Trans>Device</Trans>
</p>
<CopyText copyValue={networkDetails?.portDeviceName}>
<small className="text-default-500">{networkDetails?.portDeviceName}</small>
</CopyText>
</div>
<div className="flex flex-col gap-0.5">
<p className="text-tiny font-bold uppercase">Type</p>
<p className="text-tiny font-bold uppercase">
<Trans>Type</Trans>
</p>
<small className="text-default-500">{networkDetails?.type}</small>
</div>
</div>
Expand All @@ -97,21 +110,23 @@ function NetworkDetailsModal({
onValueChange={onSelectedChange}
>
<Checkbox classNames={checkboxClasses} value="allowManaged">
Allow Managed Addresses
<Trans>Allow Managed Addresses</Trans>
</Checkbox>
<Checkbox classNames={checkboxClasses} value="allowGlobal">
Allow Assignment of Global lPs
<Trans>Allow Assignment of Global IPs</Trans>
</Checkbox>
<Checkbox classNames={checkboxClasses} value="allowDefault">
Allow Default Router Override
<Trans>Allow Default Router Override</Trans>
</Checkbox>
<Checkbox classNames={checkboxClasses} value="allowDNS">
Allow DNS Configuration
<Trans>Allow DNS Configuration</Trans>
</Checkbox>
</CheckboxGroup>
<Divider className="my-2" />
<div className="flex flex-col gap-0.5">
<p className="text-tiny font-bold uppercase">Managed Addresses</p>
<p className="text-tiny font-bold uppercase">
<Trans>Managed Addresses</Trans>
</p>
{networkDetails?.assignedAddresses?.length ? (
networkDetails.assignedAddresses.map((address) => (
<CopyText key={address} copyValue={address}>
Expand All @@ -123,11 +138,19 @@ function NetworkDetailsModal({
)}
</div>
<div className="flex flex-col gap-0.5">
<p className="text-tiny font-bold uppercase">Managed Routes</p>
<p className="text-tiny font-bold uppercase">
<Trans>Managed Routes</Trans>
</p>
{networkDetails?.routes?.length ? (
networkDetails.routes.map((route) => (
<small className="text-default-500" key={route.target}>
{route.target} via {networkDetails.portDeviceName}
{/* i18next escapes interpolated values as HTML entities; React already escapes text */}
<Trans
values={{ target: route.target, device: networkDetails.portDeviceName }}
tOptions={{ interpolation: { escapeValue: false } }}
>
{'{{target}} via {{device}}'}
</Trans>
</small>
))
) : (
Expand Down
34 changes: 33 additions & 1 deletion src/pages/Zerotier/Networks/__tests__/ZerotierNetworks.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { fireEvent, waitFor } from '@testing-library/react'
import { fireEvent, waitFor, within } from '@testing-library/react'
import i18n from 'i18next'

import { Language } from '../../../../typings/enum.ts'
import { render } from '../../../../utils/testUtils/setupTest.tsx'
import { mockConfigIPC } from '../../../../utils/testUtils/tauriMocks.ts'
import ZerotierNetworks from '../ZerotierNetworks.tsx'
Expand All @@ -8,6 +10,10 @@ beforeEach(() => {
mockConfigIPC()
})

afterEach(async () => {
await i18n.changeLanguage(Language.en_US)
})

describe('ZerotierNetworks', () => {
it('should list the networks joined by this node', async () => {
const { getByText } = render(<ZerotierNetworks />)
Expand Down Expand Up @@ -46,4 +52,30 @@ describe('ZerotierNetworks', () => {
await waitFor(() => expect(getByText('Join New Network')).toBeTruthy())
expect(getByText('Enter 16-digit Network ID')).toBeTruthy()
})

it('should localize static labels while keeping fetched values unchanged', async () => {
await i18n.changeLanguage(Language.zh_CN)
const { findByRole, getByText } = render(<ZerotierNetworks />)

await waitFor(() => expect(getByText('882d314dd3dbd4dd')).toBeTruthy())
fireEvent.click(getByText('882d314dd3dbd4dd'))

const modal = within(await findByRole('dialog'))

expect(modal.getByText('网络 ID')).toBeTruthy()
expect(modal.getByText('名称')).toBeTruthy()
expect(modal.getByText('状态')).toBeTruthy()
expect(modal.getByText('以太网')).toBeTruthy()
expect(modal.getByText('设备')).toBeTruthy()
expect(modal.getByText('类型')).toBeTruthy()
expect(modal.getByText('允许托管地址')).toBeTruthy()
expect(modal.getByText('允许分配全局 IP')).toBeTruthy()
expect(modal.getByText('允许覆盖默认路由')).toBeTruthy()
expect(modal.getByText('允许 DNS 配置')).toBeTruthy()
expect(modal.getByText('托管地址')).toBeTruthy()
expect(modal.getByText('托管路由')).toBeTruthy()
expect(modal.getByText('172.24.0.0/24 经由 ethernet_32772')).toBeTruthy()
expect(modal.getByText('OK')).toBeTruthy()
expect(modal.getByText('PRIVATE')).toBeTruthy()
})
})
Loading