From 69370f9fdef9e9135b86ab7cac7e9f1f971f066e Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 24 Nov 2023 09:56:09 +0800 Subject: [PATCH] feat: add for i18n --- package-lock.json | 61 +++++++++++++++++++++++++++++++ package.json | 2 + src/components/editor/sidebar.tsx | 19 ++++++---- src/i18n/i18n.js | 43 ++++++++++++++++++++++ src/pages/index.tsx | 1 + 5 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 src/i18n/i18n.js diff --git a/package-lock.json b/package-lock.json index 12a6f53..0b4f296 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,6 +61,7 @@ "@tiptap/suggestion": "^2.1.12", "ai": "^2.2.25", "handlebars": "^4.7.8", + "i18next": "^23.7.6", "markdown-it": "^13.0.2", "next": "latest", "openai": "^4.20.0", @@ -69,6 +70,7 @@ "prosemirror-view": "^1.32.4", "react": "18.2.0", "react-dom": "18.2.0", + "react-i18next": "^13.5.0", "scroll-into-view-if-needed": "^3.1.0", "tippy.js": "^6.3.7" }, @@ -4346,6 +4348,14 @@ "node": ">= 0.4" } }, + "node_modules/html-parse-stringify": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/html-parse-stringify/-/html-parse-stringify-3.0.1.tgz", + "integrity": "sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg==", + "dependencies": { + "void-elements": "3.1.0" + } + }, "node_modules/humanize-ms": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", @@ -4354,6 +4364,28 @@ "ms": "^2.0.0" } }, + "node_modules/i18next": { + "version": "23.7.6", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-23.7.6.tgz", + "integrity": "sha512-O66BhXBw0fH4bEJMA0/klQKPEbcwAp5wjXEL803pdAynNbg2f4qhLIYlNHJyE7icrL6XmSZKPYaaXwy11kJ6YQ==", + "funding": [ + { + "type": "individual", + "url": "https://locize.com" + }, + { + "type": "individual", + "url": "https://locize.com/i18next.html" + }, + { + "type": "individual", + "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project" + } + ], + "dependencies": { + "@babel/runtime": "^7.23.2" + } + }, "node_modules/ignore": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", @@ -6013,6 +6045,27 @@ "react": "^18.2.0" } }, + "node_modules/react-i18next": { + "version": "13.5.0", + "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-13.5.0.tgz", + "integrity": "sha512-CFJ5NDGJ2MUyBohEHxljOq/39NQ972rh1ajnadG9BjTk+UXbHLq4z5DKEbEQBDoIhUmmbuS/fIMJKo6VOax1HA==", + "dependencies": { + "@babel/runtime": "^7.22.5", + "html-parse-stringify": "^3.0.1" + }, + "peerDependencies": { + "i18next": ">= 23.2.3", + "react": ">= 16.8.0" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + }, + "react-native": { + "optional": true + } + } + }, "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", @@ -7024,6 +7077,14 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, + "node_modules/void-elements": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-3.1.0.tgz", + "integrity": "sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/vue": { "version": "3.3.8", "resolved": "https://registry.npmjs.org/vue/-/vue-3.3.8.tgz", diff --git a/package.json b/package.json index d9640b0..1515de8 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "@tiptap/suggestion": "^2.1.12", "ai": "^2.2.25", "handlebars": "^4.7.8", + "i18next": "^23.7.6", "markdown-it": "^13.0.2", "next": "latest", "openai": "^4.20.0", @@ -71,6 +72,7 @@ "prosemirror-view": "^1.32.4", "react": "18.2.0", "react-dom": "18.2.0", + "react-i18next": "^13.5.0", "scroll-into-view-if-needed": "^3.1.0", "tippy.js": "^6.3.7" }, diff --git a/src/components/editor/sidebar.tsx b/src/components/editor/sidebar.tsx index fe38c80..a1b1b38 100644 --- a/src/components/editor/sidebar.tsx +++ b/src/components/editor/sidebar.tsx @@ -1,20 +1,23 @@ import React from 'react' import * as Accordion from '@radix-ui/react-accordion' import { ChevronDownIcon } from '@radix-ui/react-icons' +import { useTranslation } from "react-i18next"; export const Sidebar: React.FC = ({ editor }) => { + const { t, i18n } = useTranslation(); + return