From f3dbf7cc5d3e6e5611df55ed8880b7bc3ddf243a Mon Sep 17 00:00:00 2001 From: Philip Okugbe <16838612+Philipinho@users.noreply.github.com> Date: Sat, 11 Jan 2025 22:11:31 +0000 Subject: [PATCH] feat: add new languages to selection (#626) * Add new languages to selection * more translations --- .../public/locales/en-US/translation.json | 9 +++- .../features/editor/extensions/extensions.ts | 2 +- .../space/components/delete-space-modal.tsx | 47 ++++++++++--------- .../components/sidebar/space-sidebar.tsx | 10 ++-- .../space/components/space-details.tsx | 2 +- .../features/space/types/space-role-data.ts | 13 ++--- ...ount-languate.tsx => account-language.tsx} | 3 ++ apps/client/src/lib/time.ts | 5 +- .../settings/account/account-preferences.tsx | 2 +- 9 files changed, 54 insertions(+), 39 deletions(-) rename apps/client/src/features/user/components/{account-languate.tsx => account-language.tsx} (88%) diff --git a/apps/client/public/locales/en-US/translation.json b/apps/client/public/locales/en-US/translation.json index 624d0316..d3e06d26 100644 --- a/apps/client/public/locales/en-US/translation.json +++ b/apps/client/public/locales/en-US/translation.json @@ -226,7 +226,11 @@ "Select a group": "Select a group", "Export all pages and attachments in this space.": "Export all pages and attachments in this space.", "Delete space": "Delete space", + "Are you sure you want to delete this space?": "Are you sure you want to delete this space?", "Delete this space with all its pages and data.": "Delete this space with all its pages and data.", + "All pages, comments, attachments and permissions in this space will be deleted irreversibly.": "All pages, comments, attachments and permissions in this space will be deleted irreversibly.", + "Confirm space name": "Confirm space name", + "Type the space name {{spaceName}} to confirm your action.": "Type the space name {{spaceName}} to confirm your action.", "Format": "Format", "Include subpages": "Include subpages", "Include attachments": "Include attachments", @@ -331,5 +335,8 @@ "Multiple": "Multiple", "Heading {{level}}": "Heading {{level}}", "Toggle title": "Toggle title", - "Write anything. Enter \"/\" for commands": "Write anything. Enter \"/\" for commands" + "Write anything. Enter \"/\" for commands": "Write anything. Enter \"/\" for commands", + "Names do not match": "Names do not match", + "Today, {{time}}": "Today, {{time}}", + "Yesterday, {{time}}": "Yesterday, {{time}}" } diff --git a/apps/client/src/features/editor/extensions/extensions.ts b/apps/client/src/features/editor/extensions/extensions.ts index 30d04d28..891f1182 100644 --- a/apps/client/src/features/editor/extensions/extensions.ts +++ b/apps/client/src/features/editor/extensions/extensions.ts @@ -64,8 +64,8 @@ import clojure from "highlight.js/lib/languages/clojure"; import fortran from "highlight.js/lib/languages/fortran"; import haskell from "highlight.js/lib/languages/haskell"; import scala from "highlight.js/lib/languages/scala"; -import i18n from "@/i18n.ts"; import { MarkdownClipboard } from "@/features/editor/extensions/markdown-clipboard.ts"; +import i18n from "i18next"; const lowlight = createLowlight(common); lowlight.register("mermaid", plaintext); diff --git a/apps/client/src/features/space/components/delete-space-modal.tsx b/apps/client/src/features/space/components/delete-space-modal.tsx index bc3ac38e..f697322d 100644 --- a/apps/client/src/features/space/components/delete-space-modal.tsx +++ b/apps/client/src/features/space/components/delete-space-modal.tsx @@ -1,27 +1,29 @@ -import { Button, Divider, Group, Modal, Text, TextInput } from '@mantine/core'; -import { useDisclosure } from '@mantine/hooks'; -import { useDeleteSpaceMutation } from '../queries/space-query'; -import { useField } from '@mantine/form'; -import { ISpace } from '../types/space.types'; -import { useNavigate } from 'react-router-dom'; -import APP_ROUTE from '@/lib/app-route'; +import { Button, Divider, Group, Modal, Text, TextInput } from "@mantine/core"; +import { useDisclosure } from "@mantine/hooks"; +import { useDeleteSpaceMutation } from "../queries/space-query"; +import { useField } from "@mantine/form"; +import { ISpace } from "../types/space.types"; +import { useNavigate } from "react-router-dom"; +import APP_ROUTE from "@/lib/app-route"; +import { Trans, useTranslation } from "react-i18next"; interface DeleteSpaceModalProps { space: ISpace; } export default function DeleteSpaceModal({ space }: DeleteSpaceModalProps) { + const { t } = useTranslation(); const [opened, { open, close }] = useDisclosure(false); const deleteSpaceMutation = useDeleteSpaceMutation(); const navigate = useNavigate(); const confirmNameField = useField({ - initialValue: '', + initialValue: "", validateOnChange: true, validate: (value) => value.trim().toLowerCase() === space.name.trim().toLocaleLowerCase() ? null - : 'Names do not match', + : t("Names do not match"), }); const handleDelete = async () => { @@ -38,46 +40,47 @@ export default function DeleteSpaceModal({ space }: DeleteSpaceModalProps) { await deleteSpaceMutation.mutateAsync({ id: space.id, slug: space.slug }); navigate(APP_ROUTE.HOME); } catch (error) { - console.error('Failed to delete space', error); + console.error("Failed to delete space", error); } }; return ( <> - All pages, comments, attachments and permissions in this space will be - deleted irreversibly. + {t( + "All pages, comments, attachments and permissions in this space will be deleted irreversibly.", + )} - Type the space name{' '} - - '{space.name}' - {' '} - to confirm your action. + }} + /> diff --git a/apps/client/src/features/space/components/sidebar/space-sidebar.tsx b/apps/client/src/features/space/components/sidebar/space-sidebar.tsx index 38e7f5f9..1df7a2c1 100644 --- a/apps/client/src/features/space/components/sidebar/space-sidebar.tsx +++ b/apps/client/src/features/space/components/sidebar/space-sidebar.tsx @@ -82,7 +82,7 @@ export function SpaceSidebar() { classes.menu, location.pathname.toLowerCase() === getSpaceUrl(spaceSlug) ? classes.activeButton - : "" + : "", )} >
@@ -119,7 +119,7 @@ export function SpaceSidebar() { {spaceAbility.can( SpaceCaslAction.Manage, - SpaceCaslSubject.Page + SpaceCaslSubject.Page, ) && ( @@ -170,7 +170,7 @@ export function SpaceSidebar() { spaceId={space.id} readOnly={spaceAbility.cannot( SpaceCaslAction.Manage, - SpaceCaslSubject.Page + SpaceCaslSubject.Page, )} />
@@ -230,7 +230,7 @@ function SpaceMenu({ spaceId, onSpaceSettings }: SpaceMenuProps) { onClick={openExportModal} leftSection={} > - Export space + {t("Export space")} diff --git a/apps/client/src/features/space/components/space-details.tsx b/apps/client/src/features/space/components/space-details.tsx index 024a1fac..fca5aaec 100644 --- a/apps/client/src/features/space/components/space-details.tsx +++ b/apps/client/src/features/space/components/space-details.tsx @@ -33,7 +33,7 @@ export default function SpaceDetails({ spaceId, readOnly }: SpaceDetailsProps) {
- Export space + {t("Export space")} {t("Export all pages and attachments in this space.")} 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 690cd9dd..1a646203 100644 --- a/apps/client/src/features/space/types/space-role-data.ts +++ b/apps/client/src/features/space/types/space-role-data.ts @@ -1,20 +1,21 @@ import { IRoleData, SpaceRole } from "@/lib/types.ts"; +import i18n from "i18next"; export const spaceRoleData: IRoleData[] = [ { - label: "Full access", + label: i18n.t("Full access"), value: SpaceRole.ADMIN, - description: "Has full access to space settings and pages", + description: i18n.t("Has full access to space settings and pages."), }, { - label: "Can edit", + label: i18n.t("Can edit"), value: SpaceRole.WRITER, - description: "Can create and edit pages in space", + description: i18n.t("Can create and edit pages in space."), }, { - label: "Can view", + label: i18n.t("Can view"), value: SpaceRole.READER, - description: "Can view pages in space but not edit", + description: i18n.t("Can view pages in space but not edit."), }, ]; diff --git a/apps/client/src/features/user/components/account-languate.tsx b/apps/client/src/features/user/components/account-language.tsx similarity index 88% rename from apps/client/src/features/user/components/account-languate.tsx rename to apps/client/src/features/user/components/account-language.tsx index 2ac61337..e2e0f36d 100644 --- a/apps/client/src/features/user/components/account-languate.tsx +++ b/apps/client/src/features/user/components/account-language.tsx @@ -42,6 +42,9 @@ function LanguageSwitcher() { label={t("Select language")} data={[ { value: "en-US", label: "English (United States)" }, + { value: "de-DE", label: "Deutsch (Germany)" }, + { value: "fr-FR", label: "Français (France)" }, + { value: "pt-BR", label: "Português (Brazilian)" }, { value: "zh-CN", label: "中文 (简体)" }, ]} value={language} diff --git a/apps/client/src/lib/time.ts b/apps/client/src/lib/time.ts index 7651f829..67ee69f3 100644 --- a/apps/client/src/lib/time.ts +++ b/apps/client/src/lib/time.ts @@ -1,5 +1,6 @@ import { formatDistanceStrict } from "date-fns"; import { format, isToday, isYesterday } from "date-fns"; +import i18n from "i18next"; export function timeAgo(date: Date) { return formatDistanceStrict(new Date(date), new Date(), { addSuffix: true }); @@ -7,9 +8,9 @@ export function timeAgo(date: Date) { export function formattedDate(date: Date) { if (isToday(date)) { - return `Today, ${format(date, "h:mma")}`; + return i18n.t("Today, {{time}}", { time: format(date, "h:mma") }); } else if (isYesterday(date)) { - return `Yesterday, ${format(date, "h:mma")}`; + return i18n.t("Yesterday, {{time}}", { time: format(date, "h:mma") }); } else { return format(date, "MMM dd, yyyy, h:mma"); } diff --git a/apps/client/src/pages/settings/account/account-preferences.tsx b/apps/client/src/pages/settings/account/account-preferences.tsx index 021ae7c1..06d62af7 100644 --- a/apps/client/src/pages/settings/account/account-preferences.tsx +++ b/apps/client/src/pages/settings/account/account-preferences.tsx @@ -1,5 +1,5 @@ import SettingsTitle from "@/components/settings/settings-title.tsx"; -import AccountLanguage from "@/features/user/components/account-languate"; +import AccountLanguage from "@/features/user/components/account-language.tsx"; import AccountTheme from "@/features/user/components/account-theme.tsx"; import PageWidthPref from "@/features/user/components/page-width-pref.tsx"; import { Divider } from "@mantine/core";