Commit a2d18086 authored by BBeretta's avatar BBeretta

feat/language-translation (small updates, Change Language on the Home Page...

feat/language-translation (small updates, Change Language on the Home Page only, reload the page to update languages urls)
parent 8e4daaf7
Pipeline #27821 failed with stages
in 8 minutes and 38 seconds
...@@ -15,7 +15,7 @@ const DECKERROR_SIDECOUNT = 0x8; ...@@ -15,7 +15,7 @@ const DECKERROR_SIDECOUNT = 0x8;
const DECKERROR_NOTAVAIL = 0x9; const DECKERROR_NOTAVAIL = 0x9;
const language = localStorage.getItem('language'); const language = localStorage.getItem('language');
const mainDeckWarining = language === 'en' ? 'The main deck should contain 40-60 cards.' : '主卡组数量应为40-60张'; const mainDeckWarining = language != 'cn' ? 'The main deck should contain 40-60 cards.' : '主卡组数量应为40-60张';
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;
......
...@@ -8,11 +8,12 @@ import { Type } from "@/ui/Shared/DeckZone"; ...@@ -8,11 +8,12 @@ import { Type } from "@/ui/Shared/DeckZone";
import { compareCards, type EditingDeck } from "./utils"; import { compareCards, type EditingDeck } from "./utils";
const language = localStorage.getItem("language"); const language = localStorage.getItem("language");
const cardTypeNotMatch = language === 'en' ? "The Card Type does not match" : "卡片种类不符合"; const cardTypeNotMatch = language != 'cn' ? "The Card Type does not match" : "卡片种类不符合";
const exceedsNumberCardsSameName = language === 'en' ? "Exceeds the number of cards with the same name" : "超过同名卡"; const exceedsNumberCardsSameName = language != 'cn' ? "Exceeds the number of cards with the same name" : "超过同名卡";
const limitCards = language === 'en' ? 'Limit of cards' : '张的上限'; const limitCards = language != 'cn' ? 'Limit of cards' : '张的上限';
const exceedsLimit = language === 'en' ? 'Exceeds the limit' : '超过'; const exceedsLimit = language != 'cn' ? 'Exceeds the limit' : '超过';
const cannotAddTokens = language === 'en' ? 'Cannot add tokens' : '不能添加衍生物'; const cannotAddTokens = language != 'cn' ? 'Cannot add tokens' : '不能添加衍生物';
export const editDeckStore = proxy({ export const editDeckStore = proxy({
deckName: "", deckName: "",
main: [] as CardMeta[], main: [] as CardMeta[],
......
...@@ -10,7 +10,6 @@ const I18NContext = createContext<I18NContextType | undefined>(undefined); ...@@ -10,7 +10,6 @@ const I18NContext = createContext<I18NContextType | undefined>(undefined);
export const I18NProvider: React.FC<{ children: React.ReactNode }> = ({ export const I18NProvider: React.FC<{ children: React.ReactNode }> = ({
children, children,
}) => { }) => {
//const [language, setLanguage] = useState<string>("cn"); // default language
const [language, setLanguage] = useState<string>(() => { const [language, setLanguage] = useState<string>(() => {
// Get the language from localStorage if it exists, otherwise default to "cn" // Get the language from localStorage if it exists, otherwise default to "cn"
return localStorage.getItem("language") || "cn"; return localStorage.getItem("language") || "cn";
...@@ -19,6 +18,9 @@ export const I18NProvider: React.FC<{ children: React.ReactNode }> = ({ ...@@ -19,6 +18,9 @@ export const I18NProvider: React.FC<{ children: React.ReactNode }> = ({
const changeLanguage = (newLanguage: string) => { const changeLanguage = (newLanguage: string) => {
setLanguage(newLanguage); setLanguage(newLanguage);
localStorage.setItem("language", newLanguage); localStorage.setItem("language", newLanguage);
//Force a reload of the page to apply the language change
window.location.reload();
}; };
useEffect(() => { useEffect(() => {
......
...@@ -107,7 +107,7 @@ export const Component = () => { ...@@ -107,7 +107,7 @@ export const Component = () => {
{i18n("DeckBuilding")} {i18n("DeckBuilding")}
</HeaderBtn> </HeaderBtn>
<span style={{ flexGrow: 1 }} /> <span style={{ flexGrow: 1 }} />
<I18NSelector /> {location.pathname === "/" && <I18NSelector />}
<span className={styles.profile}> <span className={styles.profile}>
<Dropdown <Dropdown
arrow arrow
......
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