Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Chinese(zh-cn) translations #590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/translations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
7 changes: 7 additions & 0 deletions src/translations/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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("登录");
});
});
41 changes: 41 additions & 0 deletions src/translations/zh-cn.json
Original file line number Diff line number Diff line change
@@ -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": "用户未找到"
}