Skip to content

Commit

Permalink
feat(admin-next): add custom translation
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed May 17, 2023
1 parent 5b238bf commit ba28719
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 53 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
"dev:admin": "cd server/admin && pnpm dev",
"start:service": "cd server && pnpm start:service",
"start:admin": "cd server/admin && pnpm start",
"start:admin-next": "cd server/admin-next && pnpm start",
"build": "concurrently npm:build:web npm:build:server npm:build:admin && cp -r client/web/dist/* server/dist/public && cp -r client/web/dist/* server/dist/public",
"build:web": "cd client/web && pnpm build",
"build:server": "cd server && pnpm build && echo \"Install server side plugin:\" && pnpm run plugin:install com.msgbyte.tasks com.msgbyte.linkmeta com.msgbyte.github com.msgbyte.simplenotify com.msgbyte.topic com.msgbyte.agora com.msgbyte.wxpusher && mkdir -p ./dist/public && cp -r ./public/plugins ./dist/public && cp ./public/registry-be.json ./dist/public",
"build:admin": "cd server/admin && pnpm build",
"build:admin-next": "cd server/admin-next && pnpm build",
"check:type": "concurrently npm:check:type:client npm:check:type:server",
"check:type:client": "cd client/web && tsc --noEmit",
"check:type:server": "cd server && tsc --noEmit",
Expand Down
7 changes: 2 additions & 5 deletions server/admin-next/src/client/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
messageFields,
userFields,
} from './fields';
import { i18n } from './i18n';
import { httpClient } from './request';
import { TailchatNetwork } from './routes/network';
import { SocketIOAdmin } from './routes/socketio';
Expand All @@ -37,10 +38,10 @@ function App() {
basename="/admin"
dataProvider={dataProvider}
authProvider={authProvider}
i18n={i18n}
>
<Resource
name="users"
label="User"
icon={<IconUser />}
list={
<ListTable
Expand All @@ -63,7 +64,6 @@ function App() {

<Resource
name="messages"
label="Messages"
icon={<IconMessage />}
list={
<ListTable
Expand All @@ -80,7 +80,6 @@ function App() {

<Resource
name="groups"
label="Groups"
icon={<IconUserGroup />}
list={
<ListTable
Expand All @@ -97,7 +96,6 @@ function App() {

<Resource
name="file"
label="Files"
icon={<IconFile />}
list={
<ListTable
Expand All @@ -114,7 +112,6 @@ function App() {

<Resource
name="mail"
label="Mails"
icon={<IconEmail />}
list={<ListTable fields={mailFields} />}
/>
Expand Down
46 changes: 13 additions & 33 deletions server/admin-next/src/client/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import {
createDateTimeField,
createUrlField,
emailValidator,
createNumberField,
} from 'tushan';
import { createFileSizeField } from './components/field/filesize';

export const userFields = [
createTextField('id', {
label: 'ID',
list: {
sort: true,
},
}),
createEmailField('email', {
label: 'Email',
edit: {
rules: [
{
Expand All @@ -30,11 +29,8 @@ export const userFields = [
],
},
}),
createTextField('nickname', {
label: 'Nickname',
}),
createTextField('nickname'),
createTextField('discriminator', {
label: 'Discriminator',
edit: {
rules: [
{
Expand All @@ -46,14 +42,9 @@ export const userFields = [
],
},
}),
createBooleanField('temporary', {
label: 'Temporary',
}),
createAvatarField('avatar', {
label: 'Avatar',
}),
createBooleanField('temporary'),
createAvatarField('avatar'),
createJSONField('settings', {
label: 'Settings',
list: {
width: 200,
},
Expand All @@ -67,15 +58,9 @@ export const userFields = [
];

export const messageFields = [
createTextField('id', {
label: 'ID',
}),
createTextField('content', {
label: 'Content',
}),
createTextField('author', {
label: 'Author',
}),
createTextField('id'),
createTextField('content'),
createTextField('author'),
createTextField('groupId'),
createTextField('converseId'),
createBooleanField('hasRecall'),
Expand All @@ -89,9 +74,7 @@ export const messageFields = [
];

export const groupFields = [
createTextField('id', {
label: 'ID',
}),
createTextField('id'),
createTextField('name'),
createTextField('owner'),
createTextField('members.length', {
Expand Down Expand Up @@ -122,9 +105,7 @@ export const fileFields = [
width: 120,
},
}),
createTextField('metaData.content-type', {
label: 'Content Type',
}),
createTextField('metaData.content-type'),
createTextField('etag'),
createTextField('userId'),
createDateTimeField('createdAt'),
Expand All @@ -133,11 +114,10 @@ export const fileFields = [
export const mailFields = [
createTextField('userId'),
createTextField('host'),
createTextField('port'),
createTextField('port'),
createTextField('secure'),
createTextField('is_success'),
createTextField('data'),
createNumberField('port'),
createBooleanField('secure'),
createBooleanField('is_success'),
createJSONField('data'),
createTextField('error'),
createDateTimeField('createdAt'),
];
151 changes: 151 additions & 0 deletions server/admin-next/src/client/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import { TushanContextProps } from 'tushan';
import { i18nEnTranslation } from 'tushan/client/i18n/resources/en';
import { i18nZhTranslation } from 'tushan/client/i18n/resources/zh';

export const i18n: TushanContextProps['i18n'] = {
languages: [
{
key: 'en',
label: 'English',
translation: {
...i18nEnTranslation,
custom: {
network: {
nodeList: 'Node List',
id: 'ID',
hostname: 'Host Name',
cpuUsage: 'CPU Usage',
ipList: 'IP List',
sdkVersion: 'SDK Version',
serviceList: 'Service List',
actionList: 'Action List',
eventList: 'Event List',
},
socketio: {
tip1: 'The server URL is:',
tip2: 'The account password is the account password of Tailchat Admin',
tip3: 'NOTICE: please check "Advanced options" then select "websocket only" and "MessagePack parser"',
btn: 'Open the Admin platform',
},
config: {
uploadFileLimit: 'Upload file limit (Byte)',
emailVerification: 'Mandatory Email Verification',
serverName: 'Server Name',
serverEntryImage: 'Server Entry Page Image',
},
},
},
},
{
key: 'zh',
label: '简体中文',
translation: {
...i18nZhTranslation,
resources: {
users: {
name: '用户管理',
fields: {
id: '用户ID',
email: '邮箱',
avatar: '头像',
username: '用户名',
password: '密码',
nickname: '昵称',
discriminator: '标识符',
temporary: '是否游客',
type: '用户类型',
settings: '用户设置',
createdAt: '创建时间',
},
},
messages: {
name: '消息管理',
fields: {
content: '内容',
author: '作者',
groupId: '群组ID',
converseId: '会话ID',
hasRecall: '撤回',
reactions: '消息反应',
createdAt: '创建时间',
},
},
groups: {
name: '群组管理',
fields: {
id: '群组ID',
name: '群组名称',
avatar: '头像',
owner: '管理员',
'members.length': '成员数量',
'panels.length': '面板数量',
roles: '角色',
config: '配置信息',
fallbackPermissions: '默认权限',
createdAt: '创建时间',
updatedAt: '更新时间',
},
},
file: {
name: '文件管理',
fields: {
objectName: '对象存储名',
url: '文件路径',
size: '文件大小',
'metaData.content-type': '文件类型',
userId: '存储用户',
createdAt: '创建时间',
},
},
mail: {
name: '邮件历史',
fields: {
userId: '用户ID',
host: '发信主机',
port: '发信端口',
secure: '是否加密',
is_success: '是否成功',
data: '数据',
error: '错误信息',
createdAt: '创建时间',
},
},
system: {
name: '系统设置',
},
network: {
name: '微服务网络',
},
socketio: {
name: 'Socket.IO 长链接',
},
},
custom: {
network: {
nodeList: '节点列表',
id: 'ID',
hostname: '主机名',
cpuUsage: 'CPU占用',
ipList: 'IP地址列表',
sdkVersion: 'SDK版本',
serviceList: '服务列表',
actionList: '操作列表',
eventList: '事件列表',
},
socketio: {
tip1: '服务器URL为:',
tip2: '账号密码为Tailchat后台的账号密码',
tip3: '注意: 请打开 "Advanced options" 并选中 "websocket only" 与 "MessagePack parser"',
btn: '打开管理平台',
},
config: {
uploadFileLimit: '上传文件限制(Byte)',
emailVerification: '邮箱强制验证',
serverName: '服务器名',
serverEntryImage: '服务器登录图',
},
},
},
},
],
};
18 changes: 13 additions & 5 deletions server/admin-next/src/client/routes/network/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import React from 'react';
import { request } from '../../request';
import _uniq from 'lodash/uniq';
import { TagItems } from '../../components/TagItems';
import { Card, Spin, Table, Typography, useAsync } from 'tushan';
import {
Card,
Spin,
Table,
Typography,
useAsync,
useTranslation,
} from 'tushan';

/**
* Tailchat 网络状态
Expand All @@ -13,6 +20,7 @@ export const TailchatNetwork: React.FC = React.memo(() => {

return data;
});
const { t } = useTranslation();

if (loading) {
return <Spin />;
Expand All @@ -21,7 +29,7 @@ export const TailchatNetwork: React.FC = React.memo(() => {
return (
<Card>
<Typography.Title heading={6}>
{'custom.network.nodeList'}
{t('custom.network.nodeList')}
</Typography.Title>

<Table
Expand Down Expand Up @@ -59,22 +67,22 @@ export const TailchatNetwork: React.FC = React.memo(() => {
/>

<Typography.Title heading={6}>
{'custom.network.serviceList'}
{t('custom.network.serviceList')}
</Typography.Title>

<div>
<TagItems items={_uniq<string>(data.services ?? [])} />
</div>

<Typography.Title heading={6}>
{'custom.network.actionList'}
{t('custom.network.actionList')}
</Typography.Title>
<div>
<TagItems items={_uniq<string>(data.actions ?? [])} />
</div>

<Typography.Title heading={6}>
{'custom.network.eventList'}
{t('custom.network.eventList')}
</Typography.Title>

<div>
Expand Down
Loading

0 comments on commit ba28719

Please sign in to comment.