Merge pull request #106 from brendan-lee/chore/chinese-translation
Add Chinese translation
This commit is contained in:
commit
e7d7cd1948
|
@ -21,6 +21,8 @@ import messages_sv from './messages_sv.json';
|
||||||
import messages_th from './messages_th.json';
|
import messages_th from './messages_th.json';
|
||||||
import messages_tr from './messages_tr.json';
|
import messages_tr from './messages_tr.json';
|
||||||
import messages_ur from './messages_ur.json';
|
import messages_ur from './messages_ur.json';
|
||||||
|
import messages_zh_CN from './messages_zh_CN.json';
|
||||||
|
import messages_zh_TW from './messages_zh_TW.json';
|
||||||
|
|
||||||
const MESSAGES = {
|
const MESSAGES = {
|
||||||
ar: messages_ar,
|
ar: messages_ar,
|
||||||
|
@ -41,9 +43,13 @@ const MESSAGES = {
|
||||||
sv: messages_sv,
|
sv: messages_sv,
|
||||||
th: messages_th,
|
th: messages_th,
|
||||||
tr: messages_tr,
|
tr: messages_tr,
|
||||||
ur: messages_ur
|
ur: messages_ur,
|
||||||
|
'zh-CN': messages_zh_CN,
|
||||||
|
'zh-TW': messages_zh_TW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const availableLocales = Object.keys(MESSAGES);
|
||||||
|
|
||||||
const i18n = new Polyglot({ allowMissing: true });
|
const i18n = new Polyglot({ allowMissing: true });
|
||||||
|
|
||||||
i18n.init = (lang, opt_messages) => {
|
i18n.init = (lang, opt_messages) => {
|
||||||
|
@ -78,6 +84,8 @@ import sv from 'timeago.js/lib/lang/sv';
|
||||||
import th from 'timeago.js/lib/lang/th';
|
import th from 'timeago.js/lib/lang/th';
|
||||||
import tr from 'timeago.js/lib/lang/tr';
|
import tr from 'timeago.js/lib/lang/tr';
|
||||||
// import ur from 'timeago.js/lib/lang/ur'; // Not currently supported by TimeAgo
|
// import ur from 'timeago.js/lib/lang/ur'; // Not currently supported by TimeAgo
|
||||||
|
import zh_CN from 'timeago.js/lib/lang/zh_CN';
|
||||||
|
import zh_TW from 'timeago.js/lib/lang/zh_TW';
|
||||||
|
|
||||||
timeago.register('ar', ar);
|
timeago.register('ar', ar);
|
||||||
timeago.register('cs', cs);
|
timeago.register('cs', cs);
|
||||||
|
@ -97,6 +105,8 @@ timeago.register('ru', ru);
|
||||||
timeago.register('sv', sv);
|
timeago.register('sv', sv);
|
||||||
timeago.register('th', th);
|
timeago.register('th', th);
|
||||||
timeago.register('tr', tr);
|
timeago.register('tr', tr);
|
||||||
|
timeago.register('zh-CN', zh_CN);
|
||||||
|
timeago.register('zh-TW', zh_TW);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function that allows plugins to register their
|
* Helper function that allows plugins to register their
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"Add a comment...": "添加评论...",
|
||||||
|
"Add a reply...": "添加回复...",
|
||||||
|
"Add tag...": "添加标签...",
|
||||||
|
"Cancel": "取消",
|
||||||
|
"Close": "关闭",
|
||||||
|
"Edit": "编辑",
|
||||||
|
"Delete": "删除",
|
||||||
|
"Ok": "确认"
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"Add a comment...": "添加評論...",
|
||||||
|
"Add a reply...": "添加回覆...",
|
||||||
|
"Add tag...": "添加標籤...",
|
||||||
|
"Cancel": "取消",
|
||||||
|
"Close": "關閉",
|
||||||
|
"Edit": "編輯",
|
||||||
|
"Delete": "刪除",
|
||||||
|
"Ok": "確認"
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import I18n from '../i18n';
|
import I18n, { availableLocales } from '../i18n';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to init the i18n class with a pre-defined or auto-detected locale.
|
* Helper to init the i18n class with a pre-defined or auto-detected locale.
|
||||||
|
@ -8,11 +8,14 @@ export const setLocale = (locale, opt_messages) => {
|
||||||
const l = locale === 'auto' ?
|
const l = locale === 'auto' ?
|
||||||
window.navigator.userLanguage || window.navigator.language : locale;
|
window.navigator.userLanguage || window.navigator.language : locale;
|
||||||
|
|
||||||
try {
|
const fallback = l.split('-')[0].toLowerCase();
|
||||||
I18n.init(l.split('-')[0].toLowerCase(), opt_messages);
|
const foundLocale = [l, fallback].find(_l => availableLocales.includes(_l));
|
||||||
} catch (error) {
|
|
||||||
|
if (!foundLocale) {
|
||||||
console.warn(`Unsupported locale '${l}'. Falling back to default en.`);
|
console.warn(`Unsupported locale '${l}'. Falling back to default en.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
I18n.init(foundLocale, opt_messages);
|
||||||
} else {
|
} else {
|
||||||
I18n.init(null, opt_messages);
|
I18n.init(null, opt_messages);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue