From cc667567aae81940148789277e420d8123163907 Mon Sep 17 00:00:00 2001 From: keman5 Date: Fri, 30 Jun 2023 11:45:05 +0800 Subject: [PATCH] Add Chinese(zh-cn) translations --- README.md | 4 ++-- src/translations/index.js | 3 ++- src/translations/index.test.js | 7 ++++++ src/translations/zh-cn.json | 41 ++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/translations/zh-cn.json diff --git a/README.md b/README.md index 91f44daba..2289be5ef 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ netlifyIdentity.close(); netlifyIdentity.logout(); // Refresh the user's JWT -// Call in on('login') handler to ensure token refreshed after it expires (1hr) +// Call in on('login') handler to ensure token refreshed after it expires (1hr) // Note: this method returns a promise. netlifyIdentity.refresh().then((jwt)=>console.log(jwt)) @@ -157,7 +157,7 @@ module API. Options include: container: '#some-query-selector'; // container to attach to APIUrl: 'https://www.example.com/.netlify/functions/identity'; // Absolute url to endpoint. ONLY USE IN SPECIAL CASES! namePlaceholder: 'some-placeholder-for-Name'; // custom placeholder for name input form - locale: 'en'; // language code for translations - available: en, fr, es, pt, hu, pl, cs, sk - default to en + locale: 'en'; // language code for translations - available: en, fr, es, pt, hu, pl, cs, sk, zhCN - default to en ``` Generally avoid setting the `APIUrl`. You should only set this when your app is diff --git a/src/translations/index.js b/src/translations/index.js index 1119f6f7f..ed75b4ad4 100644 --- a/src/translations/index.js +++ b/src/translations/index.js @@ -6,9 +6,10 @@ import * as pt from "./pt.json"; import * as pl from "./pl.json"; import * as cs from "./cs.json"; import * as sk from "./sk.json"; +import * as zhCN from "./zh-cn.json"; export const defaultLocale = "en"; -const translations = { en, fr, es, hu, pt, pl, cs, sk }; +const translations = { en, fr, es, hu, pt, pl, cs, sk, zhCN }; export const getTranslation = (key, locale = defaultLocale) => { const translated = translations[locale] && translations[locale][key]; diff --git a/src/translations/index.test.js b/src/translations/index.test.js index 55bb47496..da1be3839 100644 --- a/src/translations/index.test.js +++ b/src/translations/index.test.js @@ -48,6 +48,11 @@ describe("translations", () => { expect(getTranslation("log_in", "sk")).toEqual("Prihlásiť sa"); }); + it("should return translation for 'zhCN' locale", () => { + const { getTranslation } = require("./"); + expect(getTranslation("log_in", "zhCN")).toEqual("登录"); + }); + it("should return key for non existing translation", () => { const { getTranslation } = require("./"); expect(getTranslation("unknown_key")).toEqual("unknown_key"); @@ -62,6 +67,7 @@ describe("translations", () => { jest.mock("./cs.json", () => ({})); jest.mock("./sk.json", () => ({})); jest.mock("./pl.json", () => ({})); + jest.mock("./zh-cn.json", () => ({})); const { getTranslation } = require("./"); expect(getTranslation("log_in")).toEqual("Log in"); @@ -72,5 +78,6 @@ describe("translations", () => { expect(getTranslation("log_in", "pl")).toEqual("Log in"); expect(getTranslation("log_in", "cs")).toEqual("Log in"); expect(getTranslation("log_in", "sk")).toEqual("Log in"); + expect(getTranslation("log_in", "zhCN")).toEqual("登录"); }); }); diff --git a/src/translations/zh-cn.json b/src/translations/zh-cn.json new file mode 100644 index 000000000..546f52121 --- /dev/null +++ b/src/translations/zh-cn.json @@ -0,0 +1,41 @@ +{ + "log_in": "登录", + "log_out": "注销", + "logged_in_as": "已登录账号: ", + "logged_in": "已登录", + "logging_in": "正在登录", + "logging_out": "已退出", + "sign_up": "注册", + "signing_up": "正在注册", + "forgot_password": "忘记密码?", + "recover_password": "恢复密码", + "send_recovery_email": "发送恢复邮件", + "sending_recovery_email": "正在发送恢复邮件", + "never_mind": "忽略", + "update_password": "更新密码", + "updating_password": "正在更新密码", + "complete_your_signup": "完成注册", + "site_url_title": "开发模式设置", + "site_url_link_text": "清理 localhost URL", + "site_url_message": "你似乎正在运行本地服务. 请告诉我们你的 Netlify 网站的 URL.", + "site_url_label": "输入 Netlify 网站的 URL", + "site_url_placeholder": "Netlify 网站的 URL", + "site_url_submit": "设置网站 URL", + "message_confirm": "已向您的邮箱发送确认邮件,请前往邮箱查看.", + "message_password_mail": "我们已向您的帐户发送了恢复邮件,请点击此处的链接重置您的密码.", + "message_email_changed": "您的电子邮件地址已更新!", + "message_verfication_error": "验证您的帐户时出错。请重试或联系管理员", + "message_signup_disabled": "公开注册已关闭. 请联系管理员获取邀请链接.", + "form_name_placeholder": "用户名", + "form_email_label": "输入邮箱", + "form_name_label": "输入用户名", + "form_email_placeholder": "邮箱", + "form_password_label": "输入密码", + "form_password_placeholder": "密码", + "coded_by": "由 Netlify 强力驱动", + "continue_with": "继续登录", + "No user found with this email": "未找到该邮箱的用户", + "Invalid Password": "无效密码", + "Email not confirmed": "邮箱未确认", + "User not found": "用户未找到" +}