From d9ce1e2d2c7c0ed719533714acc31b65da41cb9f Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sun, 24 Mar 2024 14:38:37 +0530 Subject: [PATCH] Add new translations and update existing ones --- src/assets/locale/en/common.json | 45 +++++++++++++++++ src/components/Common/Markdown.tsx | 15 +++--- .../Common/Playground/EditMessageForm.tsx | 12 +++-- src/components/Common/Playground/Message.tsx | 12 +++-- .../Common/Playground/WebSearch.tsx | 6 ++- src/components/Common/SaveButton.tsx | 8 +-- src/components/Common/ShareBtn.tsx | 49 +++++++++++++------ src/i18n/lang/en.ts | 6 ++- 8 files changed, 116 insertions(+), 37 deletions(-) create mode 100644 src/assets/locale/en/common.json diff --git a/src/assets/locale/en/common.json b/src/assets/locale/en/common.json new file mode 100644 index 0000000..83bdabe --- /dev/null +++ b/src/assets/locale/en/common.json @@ -0,0 +1,45 @@ +{ + "save": "Save", + "saved": "Saved", + "cancel": "Cancel", + "share": { + "tooltip": { + "share": "Share" + }, + "modal": { + "title": "Share link to Chat" + }, + "form": { + "defaultValue": { + "name": "Anonymous", + "title": "Untitled chat" + }, + "title": { + "label": "Chat title", + "placeholder": "Enter Chat title", + "required": "Chat title is required" + }, + "name": { + "label": "Your name", + "placeholder": "Enter your name", + "required": "Your name is required" + }, + "btn": { + "save": "Generate Link", + "saving": "Generating Link..." + } + }, + "notification": { + "successGenerate": "Link copied to clipboard", + "failGenerate": "Failed to generate link" + } + }, + "copyToClipboard": "Copy to clipboard", + "webSearch": "Searching the web", + "regenerate": "Regenerate", + "edit": "Edit", + "saveAndSubmit": "Save & Submit", + "editMessage": { + "placeholder": "Type a message..." + } +} \ No newline at end of file diff --git a/src/components/Common/Markdown.tsx b/src/components/Common/Markdown.tsx index f3f374f..c4090e2 100644 --- a/src/components/Common/Markdown.tsx +++ b/src/components/Common/Markdown.tsx @@ -8,17 +8,11 @@ import "property-information" import React from "react" import { Tooltip } from "antd" import { CheckIcon, ClipboardIcon } from "lucide-react" +import { useTranslation } from "react-i18next" export default function Markdown({ message }: { message: string }) { const [isBtnPressed, setIsBtnPressed] = React.useState(false) - - React.useEffect(() => { - if (isBtnPressed) { - setTimeout(() => { - setIsBtnPressed(false) - }, 4000) - } - }, [isBtnPressed]) + const { t } = useTranslation("common") return ( @@ -37,11 +31,14 @@ export default function Markdown({ message }: { message: string }) {
- +
diff --git a/src/components/Common/Playground/Message.tsx b/src/components/Common/Playground/Message.tsx index abebce2..dfaeeb8 100644 --- a/src/components/Common/Playground/Message.tsx +++ b/src/components/Common/Playground/Message.tsx @@ -4,6 +4,7 @@ import { Image, Tooltip } from "antd" import { WebSearch } from "./WebSearch" import { CheckIcon, ClipboardIcon, Pen, RotateCcw } from "lucide-react" import { EditMessageForm } from "./EditMessageForm" +import { useTranslation } from "react-i18next" type Props = { message: string @@ -28,6 +29,8 @@ export const PlaygroundMessage = (props: Props) => { const [isBtnPressed, setIsBtnPressed] = React.useState(false) const [editMode, setEditMode] = React.useState(false) + const { t } = useTranslation("common") + return (
@@ -112,7 +115,8 @@ export const PlaygroundMessage = (props: Props) => { {props.isBot && ( <> {!props.hideCopy && ( - + ) } diff --git a/src/components/Common/ShareBtn.tsx b/src/components/Common/ShareBtn.tsx index 2e55914..1dfdc5f 100644 --- a/src/components/Common/ShareBtn.tsx +++ b/src/components/Common/ShareBtn.tsx @@ -8,6 +8,7 @@ import { useMutation } from "@tanstack/react-query" import { getPageShareUrl } from "~/services/ollama" import { cleanUrl } from "~/libs/clean-url" import { getUserId, saveWebshare } from "~/libs/db" +import { useTranslation } from "react-i18next" type Props = { messages: Message[] @@ -75,6 +76,7 @@ export const PlaygroundMessage = ( } export const ShareBtn: React.FC = ({ messages }) => { + const { t } = useTranslation("common") const [open, setOpen] = useState(false) const [form] = Form.useForm() const name = Form.useWatch("name", form) @@ -104,7 +106,7 @@ export const ShareBtn: React.FC = ({ messages }) => { }) }) - if (!res.ok) throw new Error("Failed to create share link") + if (!res.ok) throw new Error(t("share.notification.failGenerate")) const data = await res.json() @@ -121,18 +123,23 @@ export const ShareBtn: React.FC = ({ messages }) => { onSuccess: async (data) => { const url = data.url navigator.clipboard.writeText(url) - message.success("Link copied to clipboard") - await saveWebshare({ title: data.title, url, api_url: data.api_url, share_id: data.share_id }) + message.success(t("share.notification.successGenerate")) + await saveWebshare({ + title: data.title, + url, + api_url: data.api_url, + share_id: data.share_id + }) setOpen(false) }, onError: (error) => { - message.error(error?.message || "Failed to create share link") + message.error(error?.message || t("share.notification.failGenerate")) } }) return ( <> - +
diff --git a/src/i18n/lang/en.ts b/src/i18n/lang/en.ts index 2abc96f..7c65165 100644 --- a/src/i18n/lang/en.ts +++ b/src/i18n/lang/en.ts @@ -1,6 +1,10 @@ import option from "@/assets/locale/en/option.json"; +import optionPlayground from "@/assets/locale/en/option-playground.json"; +import common from "@/assets/locale/en/common.json"; export const en = { - option + option, + optionPlayground, + common } \ No newline at end of file