Commit 75b8dbfd authored by BBeretta's avatar BBeretta

fix: prettier adoption added

parent 19a974ef
Pipeline #27121 failed with stages
in 12 minutes and 20 seconds
import React, { createContext, useState, useContext } from 'react'; import React, { createContext, useState, useContext } from "react";
interface LanguageContextType { interface LanguageContextType {
language: string; language: string;
changeLanguage: (newLanguage: string) => void; changeLanguage: (newLanguage: string) => void;
} }
const LanguageContext = createContext<LanguageContextType | undefined>(undefined); const LanguageContext = createContext<LanguageContextType | undefined>(
undefined,
);
export const LanguageProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { export const LanguageProvider: React.FC<{ children: React.ReactNode }> = ({
const [language, setLanguage] = useState<string>('cn'); // default language children,
}) => {
const [language, setLanguage] = useState<string>("cn");
const changeLanguage = (newLanguage: string) => { const changeLanguage = (newLanguage: string) => {
setLanguage(newLanguage); setLanguage(newLanguage);
...@@ -24,7 +28,7 @@ export const LanguageProvider: React.FC<{ children: React.ReactNode }> = ({ chil ...@@ -24,7 +28,7 @@ export const LanguageProvider: React.FC<{ children: React.ReactNode }> = ({ chil
export const useLanguage = (): LanguageContextType => { export const useLanguage = (): LanguageContextType => {
const context = useContext(LanguageContext); const context = useContext(LanguageContext);
if (!context) { if (!context) {
throw new Error('useLanguage must be used within a LanguageProvider'); throw new Error("useLanguage must be used within a LanguageProvider");
} }
return context; return context;
}; };
import React, { useEffect } from 'react'; import React, { useEffect } from "react";
import { useTranslation } from 'react-i18next'; import { useTranslation } from "react-i18next";
const LanguageSelector: React.FC = () => { const LanguageSelector: React.FC = () => {
const { t, i18n } = useTranslation(); const { t, i18n } = useTranslation();
...@@ -7,7 +7,7 @@ const LanguageSelector: React.FC = () => { ...@@ -7,7 +7,7 @@ const LanguageSelector: React.FC = () => {
const onClickLanguageChange = (e: React.ChangeEvent<HTMLSelectElement>) => { const onClickLanguageChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
const language = e.target.value; const language = e.target.value;
i18n.changeLanguage(language); i18n.changeLanguage(language);
console.log('Language:: ', language); console.log("Language:: ", language);
}; };
useEffect(() => { useEffect(() => {
......
...@@ -25,41 +25,39 @@ import translationPortuguese from "./Translation/Portuguese/translation.json"; ...@@ -25,41 +25,39 @@ import translationPortuguese from "./Translation/Portuguese/translation.json";
//---Using different namespaces //---Using different namespaces
const resources = { const resources = {
cn: { cn: {
Header: translationChinese.Header, Header: translationChinese.Header,
Start: translationChinese.Start Start: translationChinese.Start,
}, },
en: { en: {
Header: translationEnglish.Header, Header: translationEnglish.Header,
Start: translationEnglish.Start Start: translationEnglish.Start,
}, },
es: { es: {
Header: translationSpanish.Header, Header: translationSpanish.Header,
Start: translationSpanish.Start Start: translationSpanish.Start,
}, },
fr: { fr: {
Header: translationFrench.Header, Header: translationFrench.Header,
Start: translationFrench.Start Start: translationFrench.Start,
}, },
jp: { jp: {
Header: translationJapanese.Header, Header: translationJapanese.Header,
Start: translationJapanese.Start Start: translationJapanese.Start,
}, },
br: { br: {
Header: translationBrazilian.Header, Header: translationBrazilian.Header,
Start: translationBrazilian.Start Start: translationBrazilian.Start,
}, },
pt: { pt: {
Header: translationPortuguese.Header, Header: translationPortuguese.Header,
Start: translationPortuguese.Start Start: translationPortuguese.Start,
}, },
} };
i18next i18next.use(initReactI18next).init({
.use(initReactI18next)
.init({
resources, resources,
lng:"cn", //default language lng: "cn", //default language
}); });
export default i18next; export default i18next;
\ No newline at end of file
...@@ -29,9 +29,9 @@ import { theme } from "@/ui/theme"; ...@@ -29,9 +29,9 @@ import { theme } from "@/ui/theme";
import { NeosRouter } from "./ui/NeosRouter"; import { NeosRouter } from "./ui/NeosRouter";
import './i18n' import "./i18n";
import { LanguageProvider } from './Language/LanguageContext'; import { LanguageProvider } from "./Language/LanguageContext";
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement, document.getElementById("root") as HTMLElement,
...@@ -39,12 +39,12 @@ const root = ReactDOM.createRoot( ...@@ -39,12 +39,12 @@ const root = ReactDOM.createRoot(
root.render( root.render(
<LanguageProvider> <LanguageProvider>
<ConfigProvider theme={theme} locale={zhCN}> <ConfigProvider theme={theme} locale={zhCN}>
<App> <App>
<ProConfigProvider dark> <ProConfigProvider dark>
<NeosRouter /> <NeosRouter />
</ProConfigProvider> </ProConfigProvider>
</App> </App>
</ConfigProvider> </ConfigProvider>
</LanguageProvider>, </LanguageProvider>,
); );
...@@ -61,7 +61,7 @@ const HeaderBtn: React.FC< ...@@ -61,7 +61,7 @@ const HeaderBtn: React.FC<
}; };
export const Component = () => { export const Component = () => {
const { t } = useTranslation('Header'); const { t } = useTranslation("Header");
// 捕获SSO登录 // 捕获SSO登录
const routerLocation = useLocation(); const routerLocation = useLocation();
...@@ -133,7 +133,7 @@ export const Component = () => { ...@@ -133,7 +133,7 @@ export const Component = () => {
href="https://mycard.moe/ygopro/arena/#/" href="https://mycard.moe/ygopro/arena/#/"
target="_blank" target="_blank"
> >
{t("DuelDatabase")} {t("DuelDatabase")}
</a> </a>
), ),
}, },
...@@ -168,4 +168,4 @@ const NeosAvatar = () => { ...@@ -168,4 +168,4 @@ const NeosAvatar = () => {
return ( return (
<Avatar size="small" src={user?.avatar_url} style={{ cursor: "pointer" }} /> <Avatar size="small" src={user?.avatar_url} style={{ cursor: "pointer" }} />
); );
}; };
\ No newline at end of file
...@@ -13,7 +13,7 @@ import { useTranslation } from "react-i18next"; ...@@ -13,7 +13,7 @@ import { useTranslation } from "react-i18next";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
export const Component: React.FC = () => { export const Component: React.FC = () => {
const { t } = useTranslation('Start'); const { t } = useTranslation("Start");
const { user } = useSnapshot(accountStore); const { user } = useSnapshot(accountStore);
return ( return (
...@@ -50,8 +50,8 @@ export const Component: React.FC = () => { ...@@ -50,8 +50,8 @@ export const Component: React.FC = () => {
Component.displayName = "Start"; Component.displayName = "Start";
const LoginBtn: React.FC<{ logined: boolean }> = ({ logined }) => { const LoginBtn: React.FC<{ logined: boolean }> = ({ logined }) => {
const { t } = useTranslation('Start'); const { t } = useTranslation("Start");
const navigate = useNavigate(); const navigate = useNavigate();
const loginViaSSO = () => const loginViaSSO = () =>
...@@ -65,8 +65,8 @@ const LoginBtn: React.FC<{ logined: boolean }> = ({ logined }) => { ...@@ -65,8 +65,8 @@ const LoginBtn: React.FC<{ logined: boolean }> = ({ logined }) => {
style={{ marginTop: "auto" }} style={{ marginTop: "auto" }}
onClick={logined ? goToMatch : loginViaSSO} onClick={logined ? goToMatch : loginViaSSO}
> >
<span>{logined ? t("StartGame") : t("LoginToGame")}</span> <span>{logined ? t("StartGame") : t("LoginToGame")}</span>
<RightOutlined /> <RightOutlined />
</SpecialButton> </SpecialButton>
); );
}; };
\ No newline at end of file
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