From 1c96a9bec775426dab3144f011b40a229e4cf860 Mon Sep 17 00:00:00 2001
From: Renkin <906155099@qq.com>
Date: Mon, 6 Nov 2023 17:53:03 +0800
Subject: [PATCH 6/8] feat: i18n update
---
src/locales/en.js | 37 +++++++-
src/locales/zh.js | 29 +++++-
src/roadmap/roadmap.jsx | 2 +-
src/solutionTemplate/index.jsx | 158 ++++++++++++++++++++-------------
4 files changed, 156 insertions(+), 70 deletions(-)
diff --git a/src/locales/en.js b/src/locales/en.js
index 2706fc6..804fdd2 100644
--- a/src/locales/en.js
+++ b/src/locales/en.js
@@ -1,6 +1,8 @@
-export const en = {
+const en = {
app: {
name: "LeetCode Cheatsheet",
+ preview: "Preview",
+ copyMdOrigin: "Click to copy MarkDown origin",
fullScreen: "Full Screen (Press ESC to exit)",
toUse: "To Use",
custom: "Custom",
@@ -55,6 +57,7 @@ export const en = {
savingProblem: "Saving problem information, please wait~",
githubAPIError:
"Failed to use Github API, has been switched to normal mode, normal mode can only automatically bring in the problem name, problem address and solution language.",
+ notYet: "Not yet",
},
problem: {
743: "743. Network Delay Time",
@@ -93,13 +96,38 @@ export const en = {
incrementalUsage: "Incremental Usage",
explain1:
"The editing function is not supported. If you need to edit, you can do so indirectly by first \"use\", then \"save\", and finally \"delete\" the original data.",
- explain2: "Templates can be used incrementally. Click the drop-down triangle of 'to use' and select Incremental Usage.",
- explain3: "The template will be generated according to the position of your mouse. For example, if your mouse is at point (100, 100), the template will be offset by (100, 100) units as a whole. If the template is not exactly at (100, 100), it means that the template itself was not created with (0, 0) as the top-left corner. When creating custom templates, it's important to keep this in mind.",
+ explain2:
+ "Templates can be used incrementally. Click the drop-down triangle of 'to use' and select Incremental Usage.",
+ explain3:
+ "The template will be generated according to the position of your mouse. For example, if your mouse is at point (100, 100), the template will be offset by (100, 100) units as a whole. If the template is not exactly at (100, 100), it means that the template itself was not created with (0, 0) as the top-left corner. When creating custom templates, it's important to keep this in mind.",
explain4: "You can also choose to use the native excalidraw directly ",
},
explanationTemplate: {
name: "Explanation Template",
+ goToTheWebsiteToUse: "Go to the website to use",
+ problemAddress: "Problem Address",
+ problemDesc: "Problem Description",
+ preKnowledge: "Pre Knowledge",
+ company: "Company",
+ thinking: "Thinking",
+ keyPoints: "Key Points",
+ languageSupport: "Language Support",
+ complexityAnalysis: "Complexity Analysis",
+ complexityDeclare: "Let n be the length of the array.",
+ timeComplexity: "Time Complexity",
+ spaceComplexity: "Space Complexity",
+ howToUse: "How to use it?",
+ programmingLanguage: "Programming Language:",
+ commonFormulas: "Common formulas (click to copy):",
+ noBackup: "No backup file found",
+ restore: "Restore last edit content",
+ backupTips:
+ "The explanation is backed up every five seconds. If you accidentally refresh the browser, you can click the restore button below to restore it. Since it is an overwrite backup, only the last edited content will be saved.",
+ afterUpdateTemplateTips:
+ "More explanation templates will be provided later.",
+ afterUpdateThemeTips:
+ "More themes and user-defined themes will be supported later.",
},
complexityQuickCheck: {
name: "Complexity Quick Check",
@@ -117,4 +145,5 @@ export const en = {
name: "About Me",
},
};
-export default en;
+// export default en;
+module.exports = en;
diff --git a/src/locales/zh.js b/src/locales/zh.js
index ba223f3..b119c5b 100644
--- a/src/locales/zh.js
+++ b/src/locales/zh.js
@@ -1,6 +1,8 @@
-export const cn = {
+const zh = {
app: {
name: "力扣加加",
+ preview: "预览",
+ copyMdOrigin:"点击复制 MarkDown 原文",
fullScreen: "全屏模式(退出请按 ESC)",
toUse: "去使用",
custom: "自定义",
@@ -52,6 +54,7 @@ export const cn = {
savingProblem: "正在存储题目信息,请稍后~",
githubAPIError:
"使用 Github API 失败,已为您切换为普通模式,普通模式仅可自动带入题目名称,题目地址以及题解语言。",
+ notYet:"暂无",
},
problem: {
743: "743. 网络延迟时间",
@@ -96,6 +99,27 @@ export const cn = {
explanationTemplate: {
name: "题解模板",
+ goToTheWebsiteToUse: "去网站使用",
+ problemAddress: "题目地址",
+ problemDesc: "题目描述",
+ preKnowledge: "前置知识",
+ company: "公司",
+ thinking: "思路",
+ keyPoints: "关键点",
+ languageSupport: "语言支持",
+ complexityAnalysis: "复杂度分析",
+ complexityDeclare: "令 n 为数组长度。",
+ timeComplexity: "时间复杂度",
+ spaceComplexity: "空间复杂度",
+ howToUse: "如何使用?",
+ programmingLanguage: "编程语言:1",
+ commonFormulas: "常用公式(点击可复制):",
+ noBackup: "没有找到任何备份文件",
+ restore: "恢复上次编辑内容",
+ backupTips: "题解每五秒备份一次,如果你不小心刷新了浏览器可以点击下方的恢复按钮还原。由于是覆盖式备份,因此仅会保存最后一次编辑的内容。",
+ afterUpdateTemplateTips: "后续考虑提供更多题解模板。",
+ afterUpdateThemeTips:"后续考虑支持更多主题,以及用户自定义主题。"
+
},
complexityQuickCheck: {
name: "复杂度速查",
@@ -113,4 +137,5 @@ export const cn = {
name: "关于我",
},
};
-export default cn;
+// export default zh;
+module.exports = zh;
diff --git a/src/roadmap/roadmap.jsx b/src/roadmap/roadmap.jsx
index 28ad061..d8deaa1 100644
--- a/src/roadmap/roadmap.jsx
+++ b/src/roadmap/roadmap.jsx
@@ -79,7 +79,7 @@ const roadmaps = {
],
code: {
language: "py",
- text: `代码参考:代码模板 - 二分法`,
+ text: "代码参考:代码模板 - 二分法",
},
keys: [
`
diff --git a/src/solutionTemplate/index.jsx b/src/solutionTemplate/index.jsx
index 61cb401..5817a9a 100644
--- a/src/solutionTemplate/index.jsx
+++ b/src/solutionTemplate/index.jsx
@@ -20,6 +20,7 @@ import {
debounce,
getCloundStorage,
} from "../utils.js";
+import { t, lang } from "../locales";
import MarkdownRender from "../components/MarkdownRender";
// import AccessToken from "../components/AccessToken";
@@ -39,6 +40,22 @@ const slogan = `
![](https://p.ipic.vip/h9nm77.jpg)`;
+const sloganEn = `
+
+> This solution template is generated by the [LeetCode Solution Template](https://leetcode-pp.github.io/leetcode-cheat/?tab=solution-template) plugin.
+
+LeetCode friends can [follow me](https://leetcode-cn.com/u/fe-lucifer/) to receive my updates in real-time~
+
+That's all for the content of this article. If you have any thoughts or comments, feel free to leave a message, and I will check and respond to them when I have time. For more algorithm techniques, you can visit my LeetCode solution repository: https://github.com/azl397985856/leetcode. It has already gained 40K stars. You can also follow my WeChat official account "LeetCode Plus Plus" to tackle the hard bone of algorithms with clear and straightforward explanations, abundant illustrations, and step-by-step guidance.
+
+Follow the WeChat official account "LeetCode Plus Plus" and strive to present the solution approach in a clear and concise language, along with numerous illustrations, to help you recognize patterns and efficiently solve problems.
+
+![](https://p.ipic.vip/h9nm77.jpg)`;
+
+const getSlogan = () => {
+ return lang === "en" ? sloganEn : slogan;
+};
+
function displayLanguage(language) {
const m = {
python: "Python",
@@ -75,52 +92,55 @@ function getTemplate({
isLucifer = false,
}) {
return `
-## 题目地址(${title})
+## ${t("Locale.explanationTemplate.problemAddress")}(${title})
${link}
-## 题目描述
+## ${t("Locale.explanationTemplate.problemDesc")}
${desc}
-## 前置知识
+## ${t("Locale.explanationTemplate.preKnowledge")}
- ${pre}
-## 公司
+## ${t("Locale.explanationTemplate.company")}
- ${company}
-## 思路
+## ${t("Locale.explanationTemplate.thinking")}
-## 关键点
+## ${t("Locale.explanationTemplate.keyPoints")}
- ${keyword}
-## 代码
+## Code
-- 语言支持:${displayLanguage(language)}
+- ${t("Locale.explanationTemplate.languageSupport")}:${displayLanguage(
+ language
+ )}
${displayLanguage(language)} Code:
-\`\`\`${language.toLocaleLowerCase() === "python3"
+\`\`\`${
+ language.toLocaleLowerCase() == "python3"
? "python"
: language.toLocaleLowerCase()
- }
+ }
${code}
\`\`\`
-**复杂度分析**
+**${t("Locale.explanationTemplate.complexityAnalysis")}**
-令 n 为数组长度。
+${t("Locale.explanationTemplate.complexityDeclare")}
-- 时间复杂度:$O(${time})$
-- 空间复杂度:$O(${space})$
+- ${t("Locale.explanationTemplate.timeComplexity")}:$O(${time})$
+- ${t("Locale.explanationTemplate.spaceComplexity")}:$O(${space})$
-${isLucifer ? slogan : ""}
+${isLucifer ? getSlogan() : ""}
`;
}
function Template({ onChange, template }) {
@@ -149,35 +169,36 @@ function Complexities({ value, onChange }) {
);
}
-const formulas = [
+const getFormulas = (lang) => [
{
formula: "$sum_{i=1}^{n}{a_i}$",
- name: "求和",
+ name: lang === "zh" ? "求和" : "sum",
logo: require("../imgs/formula/sum.svg"),
},
{
formula: "$a\\times b$",
- name: "乘法",
+ name: lang === "zh" ? "乘法" : "times",
logo: require("../imgs/formula/times.svg"),
},
{
formula: "$a\\div b$",
- name: "除法",
+ name: lang === "zh" ? "除法" : "div",
logo: require("../imgs/formula/div.svg"),
},
{
formula: "$\\frac{a}{b}$",
- name: "分数",
+ name: lang === "zh" ? "分数" : "frac",
+
logo: require("../imgs/formula/frac.svg"),
},
{
formula: "$a\\approx b$",
- name: "约等于",
+ name: lang === "zh" ? "约等于" : "approx",
logo: require("../imgs/formula/approx.svg"),
},
{
formula: "$\\sqrt a$",
- name: "根号",
+ name: lang === "zh" ? "根号" : "sqrt",
logo: require("../imgs/formula/sqrt.svg"),
},
{
@@ -191,7 +212,7 @@ $$
\right.
$$
`,
- name: "动态规划选择方程",
+ name: lang === "zh" ? "动态规划选择方程" : "Dynamic programming selection equation",
logo: require("../imgs/formula/choice.svg"),
},
];
@@ -309,14 +330,8 @@ export default class SolutionTemplate extends PureComponent {
});
}
render() {
- const {
- language,
- time,
- space,
- isLucifer,
- template,
- isloading,
- } = this.state;
+ const { language, time, space, isLucifer, template, isloading } =
+ this.state;
return (
<>
{/*
- 如何使用?
+ {t("Locale.explanationTemplate.howToUse")}
{!isInExtension() ? (
<>