Commit 8f1aa9a7 authored by BBeretta's avatar BBeretta

feat/language-translation (dev solution provided by ChunChi )

parent 677e08f2
Pipeline #27842 failed with stages
in 7 minutes and 33 seconds
...@@ -86,22 +86,27 @@ export function getCardImgUrl(code: number, back = false) { ...@@ -86,22 +86,27 @@ export function getCardImgUrl(code: number, back = false) {
return `${ASSETS_BASE}/card_back.jpg`; return `${ASSETS_BASE}/card_back.jpg`;
} }
// Define translations for different languages (I18N)
const language = localStorage.getItem("language");
let imgUrl;
switch (language) {
case "en":
case "br":
case "pt":
case "fr":
case "es":
imgUrl = NeosConfig.releaseImgUrl.replace("zh-CN", "en-US");
break;
default:
imgUrl = NeosConfig.releaseImgUrl;
break;
}
/* End of definition (I18N) */
if (isSuperReleaseCard(code)) { if (isSuperReleaseCard(code)) {
return `${NeosConfig.preReleaseImgUrl}/${code}.jpg`; return `${NeosConfig.preReleaseImgUrl}/${code}.jpg`;
} else { } else {
const language = localStorage.getItem("language"); return `${imgUrl}/${code}.jpg`;
if (
language === "en" ||
language === "br" ||
language === "pt" ||
language === "fr" ||
language === "es"
) {
NeosConfig.releaseImgUrl = NeosConfig.releaseImgUrl.replace(
"zh-CN",
"en-US",
);
}
return `${NeosConfig.releaseImgUrl}/${code}.jpg`;
} }
} }
...@@ -9,20 +9,26 @@ export async function initStrings() { ...@@ -9,20 +9,26 @@ export async function initStrings() {
const language = localStorage.getItem("language") || "cn"; const language = localStorage.getItem("language") || "cn";
//It currently only supports en-US, es-ES, ja-JP, ko-KR, zh-CN //It currently only supports en-US, es-ES, ja-JP, ko-KR, zh-CN
if ( switch (language) {
language === "en" || case "en":
language === "br" || case "br":
language === "pt" || case "pt":
language === "fr" case "fr":
) { stringsUrl = stringsUrl.replace("zh-CN", "en-US");
stringsUrl = stringsUrl.replace("zh-CN", "en-US"); break;
} else if (language === "ja") { case "ja":
stringsUrl = stringsUrl.replace("zh-CN", "ja-JP"); stringsUrl = stringsUrl.replace("zh-CN", "ja-JP");
} else if (language === "es") { break;
stringsUrl = stringsUrl.replace("zh-CN", "es-ES"); case "es":
} else if (language === "ko") { stringsUrl = stringsUrl.replace("zh-CN", "es-ES");
stringsUrl = stringsUrl.replace("zh-CN", "ko-KR"); break;
case "ko":
stringsUrl = stringsUrl.replace("zh-CN", "ko-KR");
break;
default:
break;
} }
const strings = await (await fetch(stringsUrl)).text(); const strings = await (await fetch(stringsUrl)).text();
......
...@@ -62,6 +62,24 @@ interface YgoDbs { ...@@ -62,6 +62,24 @@ interface YgoDbs {
let YGODBS: YgoDbs = { release: null, preRelease: null }; let YGODBS: YgoDbs = { release: null, preRelease: null };
//It currently only supports en-US, es-ES, ja-JP, ko-KR, zh-CN
// Function to update URLs based on the language
function updateDbUrls(info: any, language: string): void {
const languageMap: { [key: string]: string } = {
en: "en-US",
br: "en-US",
pt: "en-US",
fr: "en-US",
ja: "ja-JP",
ko: "ko-KR",
es: "es-ES",
};
const locale = languageMap[language] || "zh-CN";
info.releaseDbUrl = info.releaseDbUrl.replace("zh-CN", locale);
info.preReleaseDbUrl = info.preReleaseDbUrl.replace("zh-CN", locale);
}
// FIXME: 应该有个返回值,告诉业务方本次请求的结果,比如初始化DB失败 // FIXME: 应该有个返回值,告诉业务方本次请求的结果,比如初始化DB失败
function helper<T extends sqliteCmd>(action: sqliteAction<T>) { function helper<T extends sqliteCmd>(action: sqliteAction<T>) {
switch (action.cmd) { switch (action.cmd) {
...@@ -69,25 +87,8 @@ function helper<T extends sqliteCmd>(action: sqliteAction<T>) { ...@@ -69,25 +87,8 @@ function helper<T extends sqliteCmd>(action: sqliteAction<T>) {
const info = action.initInfo; const info = action.initInfo;
if (info) { if (info) {
const language = localStorage.getItem("language") || "cn"; const language = localStorage.getItem("language") || "cn";
//It currently only supports en-US, es-ES, ja-JP, ko-KR, zh-CN // Update URLs based on the language
if ( updateDbUrls(info, language);
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 === "ko") {
info.releaseDbUrl = info.releaseDbUrl.replace("zh-CN", "ko-KR");
info.preReleaseDbUrl = info.preReleaseDbUrl.replace("zh-CN", "ko-KR");
} else if (language === "es") {
info.releaseDbUrl = info.releaseDbUrl.replace("zh-CN", "es-ES");
info.preReleaseDbUrl = info.preReleaseDbUrl.replace("zh-CN", "es-ES");
}
const releasePromise = pfetch(info.releaseDbUrl, { const releasePromise = pfetch(info.releaseDbUrl, {
progressCallback: action.initInfo?.progressCallback, progressCallback: action.initInfo?.progressCallback,
......
...@@ -15,15 +15,58 @@ const DECKERROR_EXTRACOUNT = 0x7; ...@@ -15,15 +15,58 @@ const DECKERROR_EXTRACOUNT = 0x7;
const DECKERROR_SIDECOUNT = 0x8; const DECKERROR_SIDECOUNT = 0x8;
const DECKERROR_NOTAVAIL = 0x9; const DECKERROR_NOTAVAIL = 0x9;
const language = localStorage.getItem("language"); // Define the possible language codes (I18N)
const mainDeckWarining = type Language = "en" | "br" | "pt" | "fr" | "ja" | "ko" | "es" | "cn";
language !== "cn"
? "The main deck should contain 40-60 cards." // Define the structure for the messages (I18N)
: "主卡组数量应为40-60张"; const messages: Record<
Language,
{ mainDeckWarning: string; extraDeckWarning: string }
> = {
en: {
mainDeckWarning: "The number of Main Deck should be 40-60 cards",
extraDeckWarning: "The number of Extra Deck should be 0-15",
},
br: {
mainDeckWarning: "The number of Main Deck should be 40-60 cards",
extraDeckWarning: "The number of Extra Deck should be 0-15",
},
pt: {
mainDeckWarning: "The number of Main Deck should be 40-60 cards",
extraDeckWarning: "The number of Extra Deck should be 0-15",
},
fr: {
mainDeckWarning: "The number of Main Deck should be 40-60 cards",
extraDeckWarning: "The number of Extra Deck should be 0-15",
},
ja: {
mainDeckWarning: "The number of Main Deck should be 40-60 cards",
extraDeckWarning: "The number of Extra Deck should be 0-15",
},
ko: {
mainDeckWarning: "The number of Main Deck should be 40-60 cards",
extraDeckWarning: "The number of Extra Deck should be 0-15",
},
es: {
mainDeckWarning: "The number of Main Deck should be 40-60 cards",
extraDeckWarning: "The number of Extra Deck should be 0-15",
},
cn: {
mainDeckWarning: "主卡组数量应为40-60张",
extraDeckWarning: "额外卡组数量应为0-15张",
},
};
/* End of definition (I18N) */
export default async function handleErrorMsg(errorMsg: ygopro.StocErrorMsg) { export default async function handleErrorMsg(errorMsg: ygopro.StocErrorMsg) {
const { error_type, error_code } = errorMsg; const { error_type, error_code } = errorMsg;
playEffect(AudioActionType.SOUND_INFO); playEffect(AudioActionType.SOUND_INFO);
// Get the language from localStorage or default to 'cn' (I18N)
const language = (localStorage.getItem("language") || "cn") as Language;
const mainDeckWarning = messages[language].mainDeckWarning;
//const extraDeckWarning = messages[language].extraDeckWarning;
switch (error_type) { switch (error_type) {
case ErrorType.JOINERROR: { case ErrorType.JOINERROR: {
roomStore.errorMsg = fetchStrings(Region.System, 1403 + error_code); roomStore.errorMsg = fetchStrings(Region.System, 1403 + error_code);
...@@ -63,7 +106,7 @@ export default async function handleErrorMsg(errorMsg: ygopro.StocErrorMsg) { ...@@ -63,7 +106,7 @@ export default async function handleErrorMsg(errorMsg: ygopro.StocErrorMsg) {
break; break;
} }
case DECKERROR_MAINCOUNT: { case DECKERROR_MAINCOUNT: {
roomStore.errorMsg = mainDeckWarining; roomStore.errorMsg = mainDeckWarning;
break; break;
} }
case DECKERROR_EXTRACOUNT: { case DECKERROR_EXTRACOUNT: {
......
...@@ -7,17 +7,80 @@ import { Type } from "@/ui/Shared/DeckZone"; ...@@ -7,17 +7,80 @@ import { Type } from "@/ui/Shared/DeckZone";
import { compareCards, type EditingDeck } from "./utils"; import { compareCards, type EditingDeck } from "./utils";
const language = localStorage.getItem("language"); // Define the possible language codes (I18N)
const cardTypeNotMatch = type Language = "en" | "br" | "pt" | "fr" | "ja" | "ko" | "es" | "cn";
language !== "cn" ? "The Card Type does not match" : "卡片种类不符合";
const exceedsNumberCardsSameName = // Define the structure for the messages (I18N)
language !== "cn" const messages: Record<
? "Exceeds the number of cards with the same name" Language,
: "超过同名卡"; { cardTypeNotMatch: string; exceedsNumberCardsSameName: string, limitCards: string, exceedsLimit: string, cannotAddTokens: string }
const limitCards = language !== "cn" ? "Limit of cards" : "张的上限"; > = {
const exceedsLimit = language !== "cn" ? "Exceeds the limit" : "超过"; en: {
const cannotAddTokens = cardTypeNotMatch: "The Card Type does not match",
language !== "cn" ? "Cannot add tokens" : "不能添加衍生物"; exceedsNumberCardsSameName: "The number of Extra Deck should be 0-15",
limitCards: "Limit of cards",
exceedsLimit: "Exceeds the limit",
cannotAddTokens: "Cannot add tokens"
},
br: {
cardTypeNotMatch: "The Card Type does not match",
exceedsNumberCardsSameName: "The number of Extra Deck should be 0-15",
limitCards: "Limit of cards",
exceedsLimit: "Exceeds the limit",
cannotAddTokens: "Cannot add tokens"
},
pt: {
cardTypeNotMatch: "The Card Type does not match",
exceedsNumberCardsSameName: "The number of Extra Deck should be 0-15",
limitCards: "Limit of cards",
exceedsLimit: "Exceeds the limit",
cannotAddTokens: "Cannot add tokens"
},
fr: {
cardTypeNotMatch: "The Card Type does not match",
exceedsNumberCardsSameName: "The number of Extra Deck should be 0-15",
limitCards: "Limit of cards",
exceedsLimit: "Exceeds the limit",
cannotAddTokens: "Cannot add tokens"
},
ja: {
cardTypeNotMatch: "The Card Type does not match",
exceedsNumberCardsSameName: "The number of Extra Deck should be 0-15",
limitCards: "Limit of cards",
exceedsLimit: "Exceeds the limit",
cannotAddTokens: "Cannot add tokens"
},
ko: {
cardTypeNotMatch: "The Card Type does not match",
exceedsNumberCardsSameName: "The number of Extra Deck should be 0-15",
limitCards: "Limit of cards",
exceedsLimit: "Exceeds the limit",
cannotAddTokens: "Cannot add tokens"
},
es: {
cardTypeNotMatch: "The Card Type does not match",
exceedsNumberCardsSameName: "Exceeds the number of cards with the same name",
limitCards: "Limit of cards",
exceedsLimit: "Exceeds the limit",
cannotAddTokens: "Cannot add tokens"
},
cn: {
cardTypeNotMatch: "卡片种类不符合",
exceedsNumberCardsSameName: "超过同名卡",
limitCards: "张的上限",
exceedsLimit: "超过",
cannotAddTokens: "不能添加衍生物"
},
};
// Get the language from localStorage or default to 'cn' (I18N)
const language = (localStorage.getItem("language") || "cn") as Language;
const cardTypeNotMatch = messages[language].cardTypeNotMatch;
const exceedsNumberCardsSameName = messages[language].exceedsNumberCardsSameName;
const limitCards = messages[language].limitCards;
const exceedsLimit = messages[language].exceedsLimit;
const cannotAddTokens = messages[language].cannotAddTokens;
/* End of definition (I18N) */
export const editDeckStore = proxy({ export const editDeckStore = proxy({
deckName: "", deckName: "",
......
...@@ -16,9 +16,83 @@ const defaultProps = { isOpen: false, positions: [] }; ...@@ -16,9 +16,83 @@ const defaultProps = { isOpen: false, positions: [] };
const localStore = proxy<PositionModalProps>(defaultProps); const localStore = proxy<PositionModalProps>(defaultProps);
const language = localStorage.getItem("language"); // Define a type for translations with an index signature (I18N)
const title = language !== "cn" ? "Please select a position" : "请选择表示形式"; interface Translations {
[key: string]: {
Title: string,
FACEUP_ATTACK: string;
FACEUP_DEFENSE: string;
FACEDOWN_ATTACK: string;
FACEDOWN_DEFENSE: string;
};
}
// Retrieve language from localStorage or default to "cn"
const language = localStorage.getItem("language") || "cn";
// Define translations for different languages (I18N)
const translations: Translations = {
en: {
Title: "Please select a position",
FACEUP_ATTACK: "Face-Up Attack",
FACEUP_DEFENSE: "Face-Up Defense",
FACEDOWN_ATTACK: "Face-Down Attack",
FACEDOWN_DEFENSE: "Face-Down Defense",
},
br: {
Title: "Por favor, selecione uma posição",
FACEUP_ATTACK: "Ataque com a Face para Cima",
FACEUP_DEFENSE: "Defesa com a Face para Cima",
FACEDOWN_ATTACK: "Ataque com a Face para Baixo",
FACEDOWN_DEFENSE: "Defesa com a Face para Baixo",
},
pt: {
Title: "Por favor, selecione uma posição",
FACEUP_ATTACK: "Ataque com a Face para Cima",
FACEUP_DEFENSE: "Defesa com a Face para Cima",
FACEDOWN_ATTACK: "Ataque com a Face para Baixo",
FACEDOWN_DEFENSE: "Defesa com a Face para Baixo",
},
fr: {
Title: "Veuillez sélectionner une position",
FACEUP_ATTACK: "Attaque Face Visible",
FACEUP_DEFENSE: "Défense Face Visible",
FACEDOWN_ATTACK: "Attaque Face Cachée",
FACEDOWN_DEFENSE: "Défense Face Cachée",
},
ja: {
Title: "ポジションを選択してください",
FACEUP_ATTACK: "表側攻撃表示",
FACEUP_DEFENSE: "表側守備表示",
FACEDOWN_ATTACK: "裏側攻撃表示",
FACEDOWN_DEFENSE: "裏側守備表示",
},
ko: {
Title: "포지션을 선택해주세요",
FACEUP_ATTACK: "앞면 공격 표시",
FACEUP_DEFENSE: "앞면 수비 표시",
FACEDOWN_ATTACK: "뒷면 공격 표시",
FACEDOWN_DEFENSE: "뒷면 수비 표시",
},
es: {
Title: "Por favor, seleccione una posición",
FACEUP_ATTACK: "Ataque en Posición de Ataque",
FACEUP_DEFENSE: "Defensa en Posición de Ataque",
FACEDOWN_ATTACK: "Ataque en Posición de Defensa",
FACEDOWN_DEFENSE: "Defensa en Posición de Defensa",
},
cn: {
Title: "请选择表示形式",
FACEUP_ATTACK: "正面攻击形式",
FACEUP_DEFENSE: "正面防守形式",
FACEDOWN_ATTACK: "背面攻击形式",
FACEDOWN_DEFENSE: "背面防守形式",
},
};
// // Define translations for different languages (I18N)
// const title = language !== "cn" ? "Please select a position" : "请选择表示形式";
// const test = translations[language].Title
export const PositionModal = () => { export const PositionModal = () => {
const { isOpen, positions } = useSnapshot(localStore); const { isOpen, positions } = useSnapshot(localStore);
const [selected, setSelected] = useState<ygopro.CardPosition | undefined>( const [selected, setSelected] = useState<ygopro.CardPosition | undefined>(
...@@ -27,7 +101,7 @@ export const PositionModal = () => { ...@@ -27,7 +101,7 @@ export const PositionModal = () => {
return ( return (
<NeosModal <NeosModal
title={title} title={translations[language].Title}
open={isOpen} open={isOpen}
footer={ footer={
<Button <Button
...@@ -63,24 +137,22 @@ export const PositionModal = () => { ...@@ -63,24 +137,22 @@ export const PositionModal = () => {
); );
}; };
// Function to get card position based on language
function cardPosition(position: ygopro.CardPosition): string { function cardPosition(position: ygopro.CardPosition): string {
const faceUpAtk = language !== "cn" ? "Face-Up Attack" : "正面攻击形式"; const messages = translations[language];
const faceUpDef = language !== "cn" ? "Face-Up Defense" : "正面防守形式";
const faceDownAtk = language !== "cn" ? "Face-Down Attack" : "背面攻击形式";
const faceDownDef = language !== "cn" ? "Face-Down Defense" : "背面防守形式";
switch (position) { switch (position) {
case ygopro.CardPosition.FACEUP_ATTACK: { case ygopro.CardPosition.FACEUP_ATTACK: {
return faceUpAtk; return messages.FACEUP_ATTACK;;
} }
case ygopro.CardPosition.FACEUP_DEFENSE: { case ygopro.CardPosition.FACEUP_DEFENSE: {
return faceUpDef; return messages.FACEUP_DEFENSE;
} }
case ygopro.CardPosition.FACEDOWN_ATTACK: { case ygopro.CardPosition.FACEDOWN_ATTACK: {
return faceDownAtk; return messages.FACEDOWN_ATTACK;;
} }
case ygopro.CardPosition.FACEDOWN_DEFENSE: { case ygopro.CardPosition.FACEDOWN_DEFENSE: {
return faceDownDef; return messages.FACEDOWN_DEFENSE;
} }
default: { default: {
return "[?]"; return "[?]";
......
...@@ -39,22 +39,137 @@ import { openChatBox } from "../ChatBox"; ...@@ -39,22 +39,137 @@ import { openChatBox } from "../ChatBox";
const { useToken } = theme; const { useToken } = theme;
const FINISH_CANCEL_RESPONSE = -1; const FINISH_CANCEL_RESPONSE = -1;
const language = localStorage.getItem("language");
const drawPhase = language !== "cn" ? "Draw" : "抽卡阶段"; // Define the possible language codes (I18N)
const standbyPhase = language !== "cn" ? "Standhy Phase" : "准备阶段"; type Language = "en" | "br" | "pt" | "fr" | "ja" | "ko" | "es" | "cn";
const mainPhase1 = language !== "cn" ? "Main Phase 1" : "主要阶段 1";
const battlePhase = language !== "cn" ? "Battle Phase" : "战斗阶段"; // Define the structure for the messages (I18N)
const battleStart = language !== "cn" ? "Battle Start" : "战斗开始"; const messages: Record<
const battleStep = language !== "cn" ? "Battle Step" : "战斗步骤"; Language,
const damage = language !== "cn" ? "Damage Step" : "伤害步骤"; {
const damageCalc = drawPhase: string; standbyPhase: string, mainPhase1: string, battlePhase: string, battleStart: string, battleStep: string, damage: string, damageCalc: string, mainPhase2: string, endPhase: string, unknown: string
language !== "cn" }
? "Damage Step (Damage Calculation)" > = {
: "伤害步骤(伤害计算)"; en: {
const mainPhase2 = language !== "cn" ? "Main Phase 2" : "主要阶段 2"; drawPhase: "Draw",
const endPhase = language !== "cn" ? "End Phase" : "结束阶段"; standbyPhase: "Standhy Phase",
const unknown = language !== "cn" ? "Unknown" : "未知阶段"; mainPhase1: "Main Phase 1",
battlePhase: "Battle Phase",
battleStart: "Battle Start",
battleStep: "Battle Step",
damage: "Damage Step",
damageCalc: "Damage Step (Damage Calculation)",
mainPhase2: "Main Phase 2",
endPhase: "End Phase",
unknown: "Unknown"
},
br: {
drawPhase: "Compra",
standbyPhase: "Fase de Espera",
mainPhase1: "Fase Principal 1",
battlePhase: "Fase de Batalha",
battleStart: "Início da Batalha",
battleStep: "Fase da Batalha",
damage: "Fase de Dano",
damageCalc: "Fase de Dano (Cálculo de Dano)",
mainPhase2: "Fase Principal 2",
endPhase: "Fase Final",
unknown: "Desconhecido"
},
pt: {
drawPhase: "Compra",
standbyPhase: "Fase de Espera",
mainPhase1: "Fase Principal 1",
battlePhase: "Fase de Batalha",
battleStart: "Início da Batalha",
battleStep: "Fase da Batalha",
damage: "Fase de Dano",
damageCalc: "Fase de Dano (Cálculo de Dano)",
mainPhase2: "Fase Principal 2",
endPhase: "Fase Final",
unknown: "Desconhecido"
},
fr: {
drawPhase: "Pioche",
standbyPhase: "Phase de Standby",
mainPhase1: "Phase Principale 1",
battlePhase: "Phase de Bataille",
battleStart: "Début de la Bataille",
battleStep: "Étape de Bataille",
damage: "Étape de Dégâts",
damageCalc: "Étape de Dégâts (Calcul des Dégâts)",
mainPhase2: "Phase Principale 2",
endPhase: "Phase Finale",
unknown: "Inconnu"
},
ja: {
drawPhase: "ドロー",
standbyPhase: "スタンバイフェイズ",
mainPhase1: "メインフェイズ 1",
battlePhase: "バトルフェイズ",
battleStart: "バトル開始",
battleStep: "バトルステップ",
damage: "ダメージステップ",
damageCalc: "ダメージステップ(ダメージ計算)",
mainPhase2: "メインフェイズ 2",
endPhase: "エンドフェイズ",
unknown: "未知"
},
ko: {
drawPhase: "드로우",
standbyPhase: "대기 페이즈",
mainPhase1: "메인 페이즈 1",
battlePhase: "배틀 페이즈",
battleStart: "배틀 시작",
battleStep: "배틀 스텝",
damage: "데미지 스텝",
damageCalc: "데미지 스텝 (데미지 계산)",
mainPhase2: "메인 페이즈 2",
endPhase: "엔드 페이즈",
unknown: "알 수 없음"
},
es: {
drawPhase: "Robo",
standbyPhase: "Fase de Espera",
mainPhase1: "Fase Principal 1",
battlePhase: "Fase de Batalla",
battleStart: "Inicio de Batalla",
battleStep: "Paso de Batalla",
damage: "Paso de Daño",
damageCalc: "Paso de Daño (Cálculo de Daño)",
mainPhase2: "Fase Principal 2",
endPhase: "Fase Final",
unknown: "Desconocido"
},
cn: {
drawPhase: "抽卡阶段",
standbyPhase: "准备阶段",
mainPhase1: "主要阶段 1",
battlePhase: "战斗阶段",
battleStart: "战斗开始",
battleStep: "战斗步骤",
damage: "伤害步骤",
damageCalc: "伤害步骤(伤害计算)",
mainPhase2: "主要阶段 2",
endPhase: "结束阶段",
unknown: "未知阶段",
},
};
// Get the language from localStorage or default to 'cn' (I18N)
const language = (localStorage.getItem("language") || "cn") as Language;
const drawPhase = messages[language].drawPhase;
const standbyPhase = messages[language].standbyPhase;
const mainPhase1 = messages[language].mainPhase1;
const battlePhase = messages[language].battlePhase;
const battleStart = messages[language].battleStart;
const battleStep = messages[language].battleStep;
const damage = messages[language].damage;
const damageCalc = messages[language].damageCalc;
const mainPhase2 = messages[language].mainPhase2;
const endPhase = messages[language].endPhase;
const unknown = messages[language].unknown;
/* End of definition (I18N) */
// PhaseType, 中文, response, 是否显示,是否禁用 // PhaseType, 中文, response, 是否显示,是否禁用
const initialPhaseBind: [ const initialPhaseBind: [
...@@ -64,18 +179,18 @@ const initialPhaseBind: [ ...@@ -64,18 +179,18 @@ const initialPhaseBind: [
show: boolean, show: boolean,
disabled: boolean, disabled: boolean,
][] = [ ][] = [
[PhaseType.DRAW, drawPhase, -1, true, true], [PhaseType.DRAW, drawPhase, -1, true, true],
[PhaseType.STANDBY, standbyPhase, -1, true, true], [PhaseType.STANDBY, standbyPhase, -1, true, true],
[PhaseType.MAIN1, mainPhase1, -1, true, true], [PhaseType.MAIN1, mainPhase1, -1, true, true],
[PhaseType.BATTLE, battlePhase, 6, true, false], [PhaseType.BATTLE, battlePhase, 6, true, false],
[PhaseType.BATTLE_START, battleStart, 3, false, true], [PhaseType.BATTLE_START, battleStart, 3, false, true],
[PhaseType.BATTLE_STEP, battleStep, 3, false, true], [PhaseType.BATTLE_STEP, battleStep, 3, false, true],
[PhaseType.DAMAGE, damage, 3, false, true], [PhaseType.DAMAGE, damage, 3, false, true],
[PhaseType.DAMAGE_GAL, damageCalc, 3, false, true], [PhaseType.DAMAGE_GAL, damageCalc, 3, false, true],
[PhaseType.MAIN2, mainPhase2, 2, true, false], [PhaseType.MAIN2, mainPhase2, 2, true, false],
[PhaseType.END, endPhase, 7, true, false], [PhaseType.END, endPhase, 7, true, false],
[PhaseType.UNKNOWN, unknown, -1, false, true], [PhaseType.UNKNOWN, unknown, -1, false, true],
]; ];
export const Menu = () => { export const Menu = () => {
const { t: i18n } = useTranslation("Menu"); const { t: i18n } = useTranslation("Menu");
......
...@@ -4,16 +4,102 @@ import { IconFont } from "@/ui/Shared"; ...@@ -4,16 +4,102 @@ import { IconFont } from "@/ui/Shared";
import CardPosition = ygopro.CardPosition; import CardPosition = ygopro.CardPosition;
const language = localStorage.getItem("language"); // Define the possible language codes (I18N)
type Language = "en" | "br" | "pt" | "fr" | "ja" | "ko" | "es" | "cn";
// Define the structure for the messages (I18N)
const messages: Record<
Language,
{
sSet: string; summon: string, spSummon: string, posChange: string, mSet: string, activate: string, attack: string
}
> = {
en: {
sSet: "Set",
summon: "Normal Summon",
spSummon: "Special Summon",
posChange: "Change Position",
mSet: "Set",
activate: "Activate",
attack: "Attack"
},
br: {
sSet: "Setar",
summon: "Invocação Normal",
spSummon: "Invocação Especial",
posChange: "Mudar Posição",
mSet: "Setar",
activate: "Ativar",
attack: "Atacar"
},
pt: {
sSet: "Setar",
summon: "Invocação Normal",
spSummon: "Invocação Especial",
posChange: "Mudar Posição",
mSet: "Setar",
activate: "Ativar",
attack: "Atacar"
},
fr: {
sSet: "Poser",
summon: "Invocation Normale",
spSummon: "Invocation Spéciale",
posChange: "Changer de Position",
mSet: "Poser",
activate: "Activer",
attack: "Attaquer"
},
ja: {
sSet: "セット",
summon: "通常召喚",
spSummon: "特殊召喚",
posChange: "表示形式変更",
mSet: "セット",
activate: "発動",
attack: "攻撃"
},
ko: {
sSet: "세트",
summon: "일반 소환",
spSummon: "특수 소환",
posChange: "포지션 변경",
mSet: "세트",
activate: "발동",
attack: "공격"
},
es: {
sSet: "Colocar",
summon: "Invocación Normal",
spSummon: "Invocación Especial",
posChange: "Cambiar Posición",
mSet: "Colocar",
activate: "Activar",
attack: "Atacar"
},
cn: {
sSet: "后场放置",
summon: "普通召唤",
spSummon: "特殊召唤",
posChange: "改变表示形式",
mSet: "前场放置",
activate: "发动效果",
attack: "攻击",
},
};
// Get the language from localStorage or default to 'cn' (I18N)
const language = (localStorage.getItem("language") || "cn") as Language;
/* End of definition (I18N) */
export function interactTypeToString(t: InteractType): string { export function interactTypeToString(t: InteractType): string {
const sSet = language !== "cn" ? "Set" : "后场放置"; const sSet = messages[language].sSet;
const summon = language !== "cn" ? "Normal Summon" : "普通召唤"; const summon = messages[language].summon;
const spSummon = language !== "cn" ? "Special Summon" : "特殊召唤"; const spSummon = messages[language].spSummon;
const posChange = language !== "cn" ? "Change Position" : "改变表示形式"; const posChange = messages[language].posChange;
const mSet = language !== "cn" ? "Set" : "前场放置"; const mSet = messages[language].mSet;
const activate = language !== "cn" ? "Activate" : "发动效果"; const activate = messages[language].activate;
const attack = language !== "cn" ? "Attack" : "攻击"; const attack = messages[language].attack;
switch (t) { switch (t) {
case InteractType.SUMMON: case InteractType.SUMMON:
......
...@@ -86,9 +86,7 @@ const resources = { ...@@ -86,9 +86,7 @@ const resources = {
i18next.use(initReactI18next).init({ i18next.use(initReactI18next).init({
resources, resources,
lng: localStorage.getItem("language") lng: localStorage.getItem("language") ?? "cn", //default language
? localStorage.getItem("language")?.toString()
: "cn", //default language
}); });
export default i18next; export default i18next;
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