Unverified Commit b5d4b8ea authored by Ajay Kumbhare's avatar Ajay Kumbhare Committed by GitHub

fix: copy code button toast message (#1979)

* #1952 Fix incorrect localization key for sign-up failure message

* feat: add typeScript support to enforce valid translation keys

* feat: add typeScript support to enforce valid translation keys

* fix lint errors

* fix lint error

* chore: Disallow destructuring 't' from useTranslation

This commit adds a linting rule to disallow the destructuring of the 't' property from the result of the useTranslation function call. The no-restricted-syntax rule in the ESLint configuration has been updated to enforce this restriction. The intention is to promote alternative approaches like using the useTranslate hook for localization.

* fix: typo fixed for memoChat

* fix: copy code button toast message

Refactored the code for the "Copy Code" button to utilize i18 strings for displaying the success message. Replaced the hard-coded value with the appropriate i18 string "Code copied successfully."
parent e36e5823
...@@ -2,10 +2,12 @@ import copy from "copy-to-clipboard"; ...@@ -2,10 +2,12 @@ import copy from "copy-to-clipboard";
import hljs from "highlight.js"; import hljs from "highlight.js";
import { toast } from "react-hot-toast"; import { toast } from "react-hot-toast";
import { matcher } from "../matcher"; import { matcher } from "../matcher";
import { useTranslate } from "@/utils/i18n";
export const CODE_BLOCK_REG = /^```(\S*?)\s([\s\S]*?)```/; export const CODE_BLOCK_REG = /^```(\S*?)\s([\s\S]*?)```/;
const renderer = (rawStr: string) => { const renderer = (rawStr: string) => {
const t = useTranslate();
const matchResult = matcher(rawStr, CODE_BLOCK_REG); const matchResult = matcher(rawStr, CODE_BLOCK_REG);
if (!matchResult) { if (!matchResult) {
return <>{rawStr}</>; return <>{rawStr}</>;
...@@ -25,7 +27,7 @@ const renderer = (rawStr: string) => { ...@@ -25,7 +27,7 @@ const renderer = (rawStr: string) => {
const handleCopyButtonClick = () => { const handleCopyButtonClick = () => {
copy(matchResult[2]); copy(matchResult[2]);
toast.success("Copy succeed"); toast.success(t("message.succeed-copy-code"));
}; };
return ( return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment