Commit 8d8d1213 authored by BBeretta's avatar BBeretta

feat/language-translation (small changes) + logical to updates String.conf and...

feat/language-translation (small changes) + logical to updates String.conf and .cdb according language selected
parent 80d42997
...@@ -2,10 +2,26 @@ import { useConfig } from "@/config"; ...@@ -2,10 +2,26 @@ import { useConfig } from "@/config";
import { fetchCard, getCardStr } from "./cards"; import { fetchCard, getCardStr } from "./cards";
const { stringsUrl } = useConfig(); let { stringsUrl } = useConfig();
export const DESCRIPTION_LIMIT = 10000; export const DESCRIPTION_LIMIT = 10000;
export async function initStrings() { export async function initStrings() {
const language = localStorage.getItem("language") || "cn";
//It currently only supports en-US, es-ES, ja-JP, ko-KR, zh-CN
if (language === "en" || language === "br" || language === "pt" || language === "fr") {
stringsUrl = stringsUrl.replace("zh-CN", "en-US");
}
else if (language === "ja") {
stringsUrl = stringsUrl.replace("zh-CN", "ja-JP");
}
else if (language === "es") {
stringsUrl = stringsUrl.replace("zh-CN", "es-ES");
}
else if (language === "ko") {
stringsUrl = stringsUrl.replace("zh-CN", "ko-KR");
}
const strings = await (await fetch(stringsUrl)).text(); const strings = await (await fetch(stringsUrl)).text();
const lineIter = strings.split("\n"); const lineIter = strings.split("\n");
......
...@@ -68,6 +68,28 @@ function helper<T extends sqliteCmd>(action: sqliteAction<T>) { ...@@ -68,6 +68,28 @@ function helper<T extends sqliteCmd>(action: sqliteAction<T>) {
case sqliteCmd.INIT: { case sqliteCmd.INIT: {
const info = action.initInfo; const info = action.initInfo;
if (info) { if (info) {
const language = localStorage.getItem("language") || "cn";
//It currently only supports en-US, es-ES, ja-JP, ko-KR, zh-CN
if (
language === "en" ||
language === "br" ||
language === "pt" ||
language === "fr"
) {
info.releaseDbUrl = info.releaseDbUrl.replace("zh-CN", "en-US");
info.preReleaseDbUrl = info.preReleaseDbUrl.replace("zh-CN", "en-US");
} else if (language === "ja") {
info.releaseDbUrl = info.releaseDbUrl.replace("zh-CN", "ja-JP");
info.preReleaseDbUrl = info.preReleaseDbUrl.replace("zh-CN", "ja-JP");
} else if (language === "es") {
info.releaseDbUrl = info.releaseDbUrl.replace("zh-CN", "es-ES");
info.preReleaseDbUrl = info.preReleaseDbUrl.replace("zh-CN", "es-ES");
} else if (language === "ko") {
info.releaseDbUrl = info.releaseDbUrl.replace("zh-CN", "ko-KR");
info.preReleaseDbUrl = info.preReleaseDbUrl.replace("zh-CN", "ko-KR");
}
const releasePromise = pfetch(info.releaseDbUrl, { const releasePromise = pfetch(info.releaseDbUrl, {
progressCallback: action.initInfo?.progressCallback, progressCallback: action.initInfo?.progressCallback,
}).then((res) => res.arrayBuffer()); // TODO: i18n }).then((res) => res.arrayBuffer()); // TODO: i18n
......
...@@ -127,7 +127,11 @@ export const CardDetail: React.FC<{ ...@@ -127,7 +127,11 @@ export const CardDetail: React.FC<{
size="small" size="small"
items={desc.filter(Boolean).map((d, i) => ({ items={desc.filter(Boolean).map((d, i) => ({
label: label:
desc.length > 1 ? (i ? i18n("MonsterEffect") : i18n("PendulumEffect")) : i18n("CardEffect"), desc.length > 1
? i
? i18n("MonsterEffect")
: i18n("PendulumEffect")
: i18n("CardEffect"),
span: 3, span: 3,
children: <CardEffectText desc={d} />, children: <CardEffectText desc={d} />,
}))} }))}
......
...@@ -27,7 +27,7 @@ export const I18NSelector: React.FC = () => { ...@@ -27,7 +27,7 @@ export const I18NSelector: React.FC = () => {
{ value: "cn", label: "简体中文" }, { value: "cn", label: "简体中文" },
{ value: "en", label: "English" }, { value: "en", label: "English" },
{ value: "fr", label: "Français" }, { value: "fr", label: "Français" },
{ value: "jp", label: "日本語" }, { value: "ja", label: "日本語" },
{ value: "br", label: "Português do Brasil" }, { value: "br", label: "Português do Brasil" },
{ value: "pt", label: "Português" }, { value: "pt", label: "Português" },
{ value: "es", label: "Castellano" }, { value: "es", label: "Castellano" },
......
...@@ -168,5 +168,9 @@ ...@@ -168,5 +168,9 @@
"SupportsYrd3dExtension": "仅支持后缀名为yrp3d的录像文件。", "SupportsYrd3dExtension": "仅支持后缀名为yrp3d的录像文件。",
"StartReplay": "开始回放", "StartReplay": "开始回放",
"PleaseUploadReplayFile": "请先上传录像文件" "PleaseUploadReplayFile": "请先上传录像文件"
},
"Popover": {
"First": "先手",
"Second": "后手"
} }
} }
\ No newline at end of file
...@@ -168,5 +168,9 @@ ...@@ -168,5 +168,9 @@
"SupportsYrd3dExtension": "Only replay files with the .yrp3d extension are supported.", "SupportsYrd3dExtension": "Only replay files with the .yrp3d extension are supported.",
"StartReplay": "Start Replay", "StartReplay": "Start Replay",
"PleaseUploadReplayFile": "Please upload the replay file first." "PleaseUploadReplayFile": "Please upload the replay file first."
},
"Popover": {
"First": "First",
"Second": "Second"
} }
} }
\ No newline at end of file
...@@ -28,6 +28,7 @@ const resources = { ...@@ -28,6 +28,7 @@ const resources = {
Chat: translationChinese.Chat, Chat: translationChinese.Chat,
MatchModal: translationChinese.MatchModal, MatchModal: translationChinese.MatchModal,
ReplayModal: translationChinese.ReplayModal, ReplayModal: translationChinese.ReplayModal,
Popover: translationChinese.Popover,
}, },
en: { en: {
Header: translationEnglish.Header, Header: translationEnglish.Header,
...@@ -43,6 +44,7 @@ const resources = { ...@@ -43,6 +44,7 @@ const resources = {
Chat: translationEnglish.Chat, Chat: translationEnglish.Chat,
MatchModal: translationEnglish.MatchModal, MatchModal: translationEnglish.MatchModal,
ReplayModal: translationEnglish.ReplayModal, ReplayModal: translationEnglish.ReplayModal,
Popover: translationEnglish.Popover,
}, },
es: { es: {
Header: translationSpanish.Header, Header: translationSpanish.Header,
...@@ -54,7 +56,7 @@ const resources = { ...@@ -54,7 +56,7 @@ const resources = {
Start: translationFrench.Start, Start: translationFrench.Start,
Match: translationFrench.Match, Match: translationFrench.Match,
}, },
jp: { ja: {
Header: translationJapanese.Header, Header: translationJapanese.Header,
Start: translationJapanese.Start, Start: translationJapanese.Start,
Match: translationJapanese.Match, Match: translationJapanese.Match,
......
...@@ -76,7 +76,7 @@ export const TpPopover: React.FC< ...@@ -76,7 +76,7 @@ export const TpPopover: React.FC<
}> }>
> = ({ children, onSelect }) => { > = ({ children, onSelect }) => {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const { t: i18n } = useTranslation("WaitRoom");
// 需要在mora的service之中,emit一个事件,让这个组件监听到,然后打开popover // 需要在mora的service之中,emit一个事件,让这个组件监听到,然后打开popover
useEffect(() => { useEffect(() => {
eventbus.once(Task.Tp, () => { eventbus.once(Task.Tp, () => {
...@@ -91,8 +91,8 @@ export const TpPopover: React.FC< ...@@ -91,8 +91,8 @@ export const TpPopover: React.FC<
}; };
const map = { const map = {
[Tp.First]: "先手", [Tp.First]: i18n("First"),
[Tp.Second]: "后手", [Tp.Second]: i18n("Second"),
}; };
return ( return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment