From 2bef37a1d00adf593292c9485e929928367c64a4 Mon Sep 17 00:00:00 2001 From: lleohao <12764126+lleohao@users.noreply.github.com> Date: Sun, 1 Sep 2024 13:22:13 +0000 Subject: [PATCH] feat: wip support i18n --- apps/client/public/locales/en/settings.json | 5 ++- .../client/public/locales/en/translation.json | 14 ++++++++ apps/client/public/locales/zh/settings.json | 5 ++- .../client/public/locales/zh/translation.json | 14 ++++++++ .../src/components/ui/role-select-menu.tsx | 11 +++++-- .../group/components/multi-group-select.tsx | 10 ++++-- .../features/space/types/space-role-data.ts | 2 +- .../components/workspace-invite-form.tsx | 32 +++++++++++-------- .../workspace/types/user-role-data.ts | 2 +- 9 files changed, 72 insertions(+), 23 deletions(-) diff --git a/apps/client/public/locales/en/settings.json b/apps/client/public/locales/en/settings.json index a1e19862..02458dbd 100644 --- a/apps/client/public/locales/en/settings.json +++ b/apps/client/public/locales/en/settings.json @@ -98,7 +98,10 @@ "Active": "Active", "Add members": "Add members", "Search for users": "Search for users", - "No user found": "No user found" + "No user found": "No user found", + "Add groups": "Add groups", + "Search for groups": "Search for groups", + "No group found": "No group found" }, "space": { "Spaces": "Spaces", diff --git a/apps/client/public/locales/en/translation.json b/apps/client/public/locales/en/translation.json index 2ae48360..548f3541 100644 --- a/apps/client/public/locales/en/translation.json +++ b/apps/client/public/locales/en/translation.json @@ -5,6 +5,20 @@ "No pages yet": "No pages yet", "Failed to load page. An error occurred.": "Failed to load page. An error occurred." }, + "role": { + "Full access": "Full access", + "Has full access to space settings and pages.": "Has full access to space settings and pages.", + "Can edit": "Can edit", + "Can create and edit pages in space.": "Can create and edit pages in space.", + "Can view": "Can view", + "Can view pages in space but not edit.": "Can view pages in space but not edit.", + "Owner": "Owner", + "Can manage workspace": "Can manage workspace", + "Admin": "Admin", + "Can manage workspace but cannot delete it": "Can manage workspace but cannot delete it", + "Member": "Member", + "Can become members of groups and spaces in workspace": "Can become members of groups and spaces in workspace" + }, "layout": { "Home": "Home", "Workspace": "Workspace", diff --git a/apps/client/public/locales/zh/settings.json b/apps/client/public/locales/zh/settings.json index ed208ff5..6616fd70 100644 --- a/apps/client/public/locales/zh/settings.json +++ b/apps/client/public/locales/zh/settings.json @@ -98,7 +98,10 @@ "Active": "活跃", "Add members": "添加成员", "Search for users": "搜索用户", - "No user found": "未找到用户" + "No user found": "未找到用户", + "Add groups": "添加群组", + "Search for groups": "搜索群组", + "No group found": "未找到群组" }, "space": { "Spaces": "空间", diff --git a/apps/client/public/locales/zh/translation.json b/apps/client/public/locales/zh/translation.json index 61aab577..9f2d5d22 100644 --- a/apps/client/public/locales/zh/translation.json +++ b/apps/client/public/locales/zh/translation.json @@ -5,6 +5,20 @@ "No pages yet": "暂无页面", "Failed to load page. An error occurred.": "加载页面失败。发生错误。" }, + "role": { + "Full access": "完全访问", + "Has full access to space settings and pages": "具有对空间设置和页面的完全访问权限", + "Can edit": "可以编辑", + "Can create and edit pages in space": "可以在空间中创建和编辑页面", + "Can view": "可以查看", + "Can view pages in space but not edit": "可以查看空间中的页面但不能编辑", + "Owner": "所有者", + "Can manage workspace": "可以管理工作区", + "Admin": "管理员", + "Can manage workspace but cannot delete it": "可以管理工作区但不能删除它", + "Member": "成员", + "Can become members of groups and spaces in workspace": "可以成为工作区中群组和空间的成员" + }, "layout": { "Home": "首页", "Workspace": "工作区", diff --git a/apps/client/src/components/ui/role-select-menu.tsx b/apps/client/src/components/ui/role-select-menu.tsx index 0d83cb7f..9434f83c 100644 --- a/apps/client/src/components/ui/role-select-menu.tsx +++ b/apps/client/src/components/ui/role-select-menu.tsx @@ -2,6 +2,7 @@ import React, { forwardRef } from "react"; import { IconCheck, IconChevronDown } from "@tabler/icons-react"; import { Group, Text, Menu, Button } from "@mantine/core"; import { IRoleData } from "@/lib/types.ts"; +import { useTranslation } from "react-i18next"; interface RoleButtonProps extends React.ComponentPropsWithoutRef<"button"> { name: string; @@ -36,10 +37,14 @@ export default function RoleSelectMenu({ onChange, disabled, }: RoleMenuProps) { + const { t } = useTranslation("translation", { + keyPrefix: "role", + }); + return ( - + @@ -50,9 +55,9 @@ export default function RoleSelectMenu({ >
- {item.label} + {t(item.label)} - {item.description} + {t(item.description)}
{item.label === roleName && } diff --git a/apps/client/src/features/group/components/multi-group-select.tsx b/apps/client/src/features/group/components/multi-group-select.tsx index bb70a287..af750823 100644 --- a/apps/client/src/features/group/components/multi-group-select.tsx +++ b/apps/client/src/features/group/components/multi-group-select.tsx @@ -4,6 +4,7 @@ import { Group, MultiSelect, MultiSelectProps, Text } from "@mantine/core"; import { useGetGroupsQuery } from "@/features/group/queries/group-query.ts"; import { IGroup } from "@/features/group/types/group.types.ts"; import { IconUsersGroup } from "@tabler/icons-react"; +import { useTranslation } from "react-i18next"; interface MultiGroupSelectProps { onChange: (value: string[]) => void; @@ -29,6 +30,9 @@ export function MultiGroupSelect({ description, mt, }: MultiGroupSelectProps) { + const { t } = useTranslation("settings", { + keyPrefix: "workspace.group", + }); const [searchValue, setSearchValue] = useState(""); const [debouncedQuery] = useDebouncedValue(searchValue, 500); const { data: groups, isLoading } = useGetGroupsQuery({ @@ -64,8 +68,8 @@ export function MultiGroupSelect({ hidePickedOptions maxDropdownHeight={300} description={description} - label={label || "Add groups"} - placeholder="Search for groups" + label={label || t("Add groups")} + placeholder={t("Search for groups")} mt={mt} searchable searchValue={searchValue} @@ -73,7 +77,7 @@ export function MultiGroupSelect({ clearable variant="filled" onChange={onChange} - nothingFoundMessage="No group found" + nothingFoundMessage={t("No group found")} maxValues={50} /> ); diff --git a/apps/client/src/features/space/types/space-role-data.ts b/apps/client/src/features/space/types/space-role-data.ts index 40ae9ae2..690cd9dd 100644 --- a/apps/client/src/features/space/types/space-role-data.ts +++ b/apps/client/src/features/space/types/space-role-data.ts @@ -9,7 +9,7 @@ export const spaceRoleData: IRoleData[] = [ { label: "Can edit", value: SpaceRole.WRITER, - description: "Can create and edit pages in space.", + description: "Can create and edit pages in space", }, { label: "Can view", diff --git a/apps/client/src/features/workspace/components/members/components/workspace-invite-form.tsx b/apps/client/src/features/workspace/components/members/components/workspace-invite-form.tsx index c6de5c6c..cc402ef6 100644 --- a/apps/client/src/features/workspace/components/members/components/workspace-invite-form.tsx +++ b/apps/client/src/features/workspace/components/members/components/workspace-invite-form.tsx @@ -11,9 +11,7 @@ interface Props { onClose: () => void; } export function WorkspaceInviteForm({ onClose }: Props) { - const { t } = useTranslation("settings", { - keyPrefix: "workspace.member", - }); + const { t } = useTranslation(["settings", "translation"]); const [emails, setEmails] = useState([]); const [role, setRole] = useState(UserRole.MEMBER); const [groupIds, setGroupIds] = useState([]); @@ -49,10 +47,10 @@ export function WorkspaceInviteForm({ onClose }: Props) { role.value !== UserRole.OWNER)} + data={userRoleData + .filter((role) => role.value !== UserRole.OWNER) + .map((role) => ({ + ...role, + label: t(`role.${role.label}`, { ns: "translation" }), + description: t(`role.${role.description}`, { ns: "translation" }), + }))} defaultValue={UserRole.MEMBER} allowDeselect={false} checkIconPosition="right" @@ -76,9 +82,9 @@ export function WorkspaceInviteForm({ onClose }: Props) { @@ -87,7 +93,7 @@ export function WorkspaceInviteForm({ onClose }: Props) { onClick={handleSubmit} loading={createInvitationMutation.isPending} > - {t("Send invitation")} + {t("workspace.member.Send invitation")}
diff --git a/apps/client/src/features/workspace/types/user-role-data.ts b/apps/client/src/features/workspace/types/user-role-data.ts index 564043f4..9418206f 100644 --- a/apps/client/src/features/workspace/types/user-role-data.ts +++ b/apps/client/src/features/workspace/types/user-role-data.ts @@ -14,7 +14,7 @@ export const userRoleData: IRoleData[] = [ { label: "Member", value: UserRole.MEMBER, - description: "Can become members of groups and spaces in workspace.", + description: "Can become members of groups and spaces in workspace", }, ];