feat(web): i18n with react-i18next (sv/en)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-03 22:42:47 +02:00
parent 66d0624279
commit 478b4ce44e
10 changed files with 156 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import { expect, test, beforeEach } from "vitest";
import { render, screen, act } from "@testing-library/react";
import { useTranslation } from "react-i18next";
import i18n from "./index";
import { useLocale } from "./use-locale";
beforeEach(async () => {
await i18n.changeLanguage("en");
});
function Probe() {
const { t } = useTranslation();
const { setLocale } = useLocale();
return (
<div>
<span data-testid="title">{t("objects.title")}</span>
<button onClick={() => setLocale("sv")}>sv</button>
</div>
);
}
test("switches language at runtime", async () => {
render(<Probe />);
expect(screen.getByTestId("title")).toHaveTextContent("Objects");
await act(async () => {
screen.getByRole("button", { name: "sv" }).click();
});
expect(screen.getByTestId("title")).toHaveTextContent("Föremål");
});