language switcher

This commit is contained in:
caranicas 2022-09-19 15:52:51 -04:00
parent 1ac8eba1b8
commit e0a4f0bc4c
5 changed files with 51 additions and 20 deletions

View File

@ -1,11 +1,15 @@
import i18n from "i18next";
// this should be updated to an interface
import translation from "./locales/en/home.json";
import ENTranslation from "./locales/en/home.json";
import ESTranlation from "./locales/es/home.json";
import { initReactI18next } from "react-i18next";
export const resources = {
en: {
translation,
translation: ENTranslation,
},
es: {
translation: ESTranlation,
},
} as const;

View File

@ -1,5 +1,5 @@
{
"title": "Stable Diffusion UI",
"title": "Stable Diffusion UI en Español",
"description": "",
"navbar": {},
"land-cre": {},

View File

@ -11,6 +11,8 @@ import {
HeaderDisplayMain, // @ts-expect-error
} from "./headerDisplay.css.ts";
import LanguageDropdown from "./languageDropdown";
export default function HeaderDisplay() {
const { t } = useTranslation();
@ -43,6 +45,8 @@ export default function HeaderDisplay() {
{t("title")} {version} {release}{" "}
</h1>
<StatusDisplay className="status-display"></StatusDisplay>
<LanguageDropdown></LanguageDropdown>
</div>
);
}

View File

@ -0,0 +1,23 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
const LanguageDropdown = () => {
const { i18n } = useTranslation();
const [language, setLanguage] = useState("id");
const handleLangChange = (evt: any) => {
const lang = evt.target.value;
console.log(lang);
setLanguage(lang);
i18n.changeLanguage(lang);
};
return (
<select onChange={handleLangChange} value={language}>
<option value="en">EN</option>
<option value="es">ES</option>
</select>
);
};
export default LanguageDropdown;

File diff suppressed because one or more lines are too long