From 7a74b371a138382ab5a00a5eee6362fb3a1fcd1b Mon Sep 17 00:00:00 2001 From: lys <971387674@qq.com> Date: Wed, 12 Feb 2025 14:07:32 +0800 Subject: [PATCH] master --- package.json | 1 + src/locales/en-US.ts | 112 +++++++++--------- src/locales/zh-CN.ts | 112 +++++++++--------- src/pages/exception/403/index.tsx | 1 + .../components/preview/index.tsx | 3 +- src/pages/hiprintDesign/index.tsx | 4 +- src/utils/locale.tsx | 26 ++-- 7 files changed, 132 insertions(+), 127 deletions(-) diff --git a/package.json b/package.json index e3ac2ba..639ddf6 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "devDependencies": { "@types/react": "^17.0.2", "@types/react-dom": "^17.0.2", + "@types/store": "^2.0.5", "@umijs/plugin-access": "2.4.2", "@umijs/plugin-dva": "^0.13.0", "@umijs/plugin-initial-state": "^2.4.0", diff --git a/src/locales/en-US.ts b/src/locales/en-US.ts index 9e53ee9..2026ab8 100644 --- a/src/locales/en-US.ts +++ b/src/locales/en-US.ts @@ -1,58 +1,58 @@ export default { - '403': "Sorry, you don't have access to this page.", - '404': 'Sorry, the page you visited does not exist.', - '500': 'Sorry, the server is reporting an error.', - BackToHome: 'Back to home', - 'Add Param': 'Add Param', - Address: 'Address', - Age: 'Age', - 'Are you sure delete this record?': 'Are you sure delete this record?', - Author: 'Author', - Avatar: 'Avatar', - Categories: 'Categories', - 'Clear notifications': 'Clear notifications', - Comments: 'Comments', - Create: 'Create', - 'Create User': 'Create User', - CreateTime: 'CreateTime', - Dark: 'Dark', - Delete: 'Delete', - Email: 'Email', - Female: 'Female', - Gender: 'Gender', - 'Hi,': 'Hi,', - Image: 'Image', - Light: 'Light', - Male: 'Male', - Name: 'Name', - NickName: 'NickName', - 'Not Found': 'Not Found', - Operation: 'Operation', - Params: 'Params', - Password: 'Password', - Phone: 'Phone', - 'Pick an address': 'Pick an address', - 'Please pick an address': 'Please pick an address', - Publised: 'Publised', - 'Publish Date': 'Publish Date', - Reset: 'Reset', - Search: 'Search', - 'Search Name': 'Search Name', - Send: 'Send', - 'Sign in': 'Sign in', - 'Sign out': 'Sign out', - 'Switch Theme': 'Switch Theme', - Tags: 'Tags', - 'The input is not valid E-mail!': 'The input is not valid E-mail!', - 'The input is not valid phone!': 'The input is not valid phone!', - Title: 'Title', - 'Total {total} Items': 'Total {total} Items', - Unpublished: 'Unpublished', - Update: 'Update', - 'Update User': 'Update User', - Username: 'Username', - RememberMe: 'Remember me', - Views: 'Views', - Visibility: 'Visibility', - 'You have viewed all notifications.': 'You have viewed all notifications.', + "403": "Sorry, you don't have access to this page.", + "404": "Sorry, the page you visited does not exist.", + "500": "Sorry, the server is reporting an error.", + BackToHome: "Back to home", + "Add Param": "Add Param", + Address: "Address", + Age: "Age", + "Are you sure delete this record?": "Are you sure delete this record?", + Author: "Author", + Avatar: "Avatar", + Categories: "Categories", + "Clear notifications": "Clear notifications", + Comments: "Comments", + Create: "Create", + "Create User": "Create User", + CreateTime: "CreateTime", + Dark: "Dark", + Delete: "Delete", + Email: "Email", + Female: "Female", + Gender: "Gender", + "Hi,": "Hi,", + Image: "Image", + Light: "Light", + Male: "Male", + Name: "Name", + NickName: "NickName", + "Not Found": "Not Found", + Operation: "Operation", + Params: "Params", + Password: "Password", + Phone: "Phone", + "Pick an address": "Pick an address", + "Please pick an address": "Please pick an address", + Publised: "Publised", + "Publish Date": "Publish Date", + Reset: "Reset", + Search: "Search", + "Search Name": "Search Name", + Send: "Send", + "Sign in": "Sign in", + "Sign out": "Sign out", + "Switch Theme": "Switch Theme", + Tags: "Tags", + "The input is not valid E-mail!": "The input is not valid E-mail!", + "The input is not valid phone!": "The input is not valid phone!", + Title: "Title", + "Total {total} Items": "Total {total} Items", + Unpublished: "Unpublished", + Update: "Update", + "Update User": "Update User", + Username: "Username", + RememberMe: "Remember me", + Views: "Views", + Visibility: "Visibility", + "You have viewed all notifications.": "You have viewed all notifications." }; diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 78e9b0d..2649428 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -1,58 +1,58 @@ export default { - '403': '您无权访问此页面。', - '404': '您所访问的地址不存在。', - '500': '发生了服务器错误,请联系管理员处理。', - BackToHome: '返回首页', - 'Add Param': '添加参数', - Address: '地址', - Age: '年龄', - 'Are you sure delete this record?': '您确定要删除这条记录吗?', - Author: '作者', - Avatar: '头像', - Categories: '类别', - 'Clear notifications': '清空消息', - Comments: '评论数', - Create: '创建', - 'Create User': '创建用户', - CreateTime: '创建时间', - Dark: '暗', - Delete: '删除', - Email: '电子邮件', - Female: '女', - Gender: '性别', - 'Hi,': '你好,', - Image: '图像', - Light: '明', - Male: '男性', - Name: '名字', - NickName: '昵称', - 'Not Found': '未找到', - Operation: '操作', - Params: '参数', - Password: '密码', - Phone: '电话', - 'Pick an address': '选择地址', - 'Please pick an address': '选择地址', - Publised: '已发布', - 'Publish Date': '发布日期', - Reset: '重置', - Search: '搜索', - 'Search Name': '搜索名字', - Send: '发送', - 'Sign in': '登录', - 'Sign out': '退出登录', - 'Switch Theme': '切换主题', - Tags: '标签', - 'The input is not valid E-mail!': '输入的电子邮件无效!', - 'The input is not valid phone!': '输入无效的手机!', - Title: '标题', - 'Total {total} Items': '总共 {total} 条记录', - Unpublished: '未发布', - Update: '更新', - 'Update User': '更新用户', - Username: '用户名', - RememberMe: '记住我', - Views: '浏览数', - Visibility: '可见性', - 'You have viewed all notifications.': '您已查看所有通知', + "403": "您无权访问此页面。", + "404": "您所访问的地址不存在。", + "500": "发生了服务器错误,请联系管理员处理。", + BackToHome: "返回首页", + "Add Param": "添加参数", + Address: "地址", + Age: "年龄", + "Are you sure delete this record?": "您确定要删除这条记录吗?", + Author: "作者", + Avatar: "头像", + Categories: "类别", + "Clear notifications": "清空消息", + Comments: "评论数", + Create: "创建", + "Create User": "创建用户", + CreateTime: "创建时间", + Dark: "暗", + Delete: "删除", + Email: "电子邮件", + Female: "女", + Gender: "性别", + "Hi,": "你好,", + Image: "图像", + Light: "明", + Male: "男性", + Name: "名字", + NickName: "昵称", + "Not Found": "未找到", + Operation: "操作", + Params: "参数", + Password: "密码", + Phone: "电话", + "Pick an address": "选择地址", + "Please pick an address": "选择地址", + Publised: "已发布", + "Publish Date": "发布日期", + Reset: "重置", + Search: "搜索", + "Search Name": "搜索名字", + Send: "发送", + "Sign in": "登录", + "Sign out": "退出登录", + "Switch Theme": "切换主题", + Tags: "标签", + "The input is not valid E-mail!": "输入的电子邮件无效!", + "The input is not valid phone!": "输入无效的手机!", + Title: "标题", + "Total {total} Items": "总共 {total} 条记录", + Unpublished: "未发布", + Update: "更新", + "Update User": "更新用户", + Username: "用户名", + RememberMe: "记住我", + Views: "浏览数", + Visibility: "可见性", + "You have viewed all notifications.": "您已查看所有通知" }; diff --git a/src/pages/exception/403/index.tsx b/src/pages/exception/403/index.tsx index 2498866..3cb1015 100644 --- a/src/pages/exception/403/index.tsx +++ b/src/pages/exception/403/index.tsx @@ -1,5 +1,6 @@ import { useIntl, Link } from 'umi'; import { Result, Button } from 'antd'; +import React from "react"; export default () => { const intl = useIntl(); diff --git a/src/pages/hiprintDesign/components/preview/index.tsx b/src/pages/hiprintDesign/components/preview/index.tsx index b9c001b..4eeebfb 100644 --- a/src/pages/hiprintDesign/components/preview/index.tsx +++ b/src/pages/hiprintDesign/components/preview/index.tsx @@ -6,6 +6,7 @@ import { DownloadOutlined, PrinterOutlined } from "@ant-design/icons"; import { useMobStore } from "@/hooks"; import { toJS } from "mobx"; import styles from "./index.less"; +import Trans from "@/utils/locale"; interface IProps extends DrawerProps {} @@ -44,7 +45,7 @@ const Index: React.FC = observer((props) => { 打印 } diff --git a/src/pages/hiprintDesign/index.tsx b/src/pages/hiprintDesign/index.tsx index a908e1a..afc4c55 100644 --- a/src/pages/hiprintDesign/index.tsx +++ b/src/pages/hiprintDesign/index.tsx @@ -9,7 +9,7 @@ import { useMobStore } from "@/hooks"; import * as hiprintConfig from "./config"; import classnames from "classnames"; import styles from "./index.less"; - +import Trans from "@/utils/locale"; const { Header, Sider, Content } = Layout; interface OwnProps {} @@ -88,7 +88,7 @@ const Design: FunctionComponent = observer((props) => { )} diff --git a/src/utils/locale.tsx b/src/utils/locale.tsx index 2b142a9..6d34648 100644 --- a/src/utils/locale.tsx +++ b/src/utils/locale.tsx @@ -1,19 +1,20 @@ -import * as React from 'react'; -import moment from 'moment'; -import store from 'store'; -import { useIntl } from 'umi'; -import { i18n } from './config'; +import * as React from "react"; +import moment from "moment"; +import store from "store"; +import { useIntl } from "umi"; +import { i18n } from "./config"; export const languages = i18n ? i18n.languages.map((item) => item.key) : []; -export const defaultLanguage = i18n ? i18n.defaultLanguage : ''; +export const defaultLanguage = i18n ? i18n.defaultLanguage : ""; + export function getLocale() { - return store.get('locale') || defaultLanguage; + return store.get("locale") || defaultLanguage; } export function setLocale(language: string) { if (getLocale() !== language) { - moment.locale(language === 'zh-CN' ? 'zh-CN' : language); - store.set('locale', language); + moment.locale(language === "zh-CN" ? "zh-CN" : language); + store.set("locale", language); window.location.reload(); } } @@ -21,7 +22,8 @@ export function setLocale(language: string) { interface ITransProps { children: string; } -const Trans: React.FC = ({ children }: any) => { + +export default function Trans({ children }: ITransProps) { const intl = useIntl(); - return intl.formatMessage({ id: children }); -}; + return <>{intl.formatMessage({ id: children })}; +}