I18n: infrastruktura w panelu admina (i18next+react-i18next, detekcja jezyka PL/EN, przelacznik, testy przymuszone do PL)

This commit is contained in:
tisachi
2026-10-17 09:58:42 +02:00
parent 807d2151a2
commit 3a593feb82
19 changed files with 316 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ import {
import { useAuth } from '../store/auth';
import { useIsTrainer } from '../api/queries';
import { APP_URL } from '../config';
import { Button, ThemeToggle } from './ui';
import { Button, ThemeToggle, LanguageToggle } from './ui';
import { Topbar } from '../topbar';
import { Brandmark } from './Brandmark';
import { Avatar } from './Avatar';
@@ -207,6 +207,7 @@ export default function Layout() {
</div>
<div className="flex items-center gap-2">
<ThemeToggle />
<LanguageToggle />
<Button variant="secondary" size="sm" className="flex-1" onClick={doLogout}>
<LogOut className="w-4 h-4" />
Wyloguj
@@ -220,6 +221,7 @@ export default function Layout() {
<div className="mt-auto flex flex-col items-center gap-2.5 border-t border-line px-2 pb-4 pt-3">
<Avatar name={fullName} size={32} />
<ThemeToggle />
<LanguageToggle />
<button
type="button"
onClick={doLogout}

View File

@@ -22,6 +22,7 @@ export * from './ui/typography';
export * from './ui/content';
export * from './ui/dialogs';
export * from './ui/theme-toggle';
export * from './ui/language-toggle';
/* Button */
export type ButtonVariant = 'primary' | 'secondary' | 'danger' | 'ghost';
@@ -53,7 +54,11 @@ export function Badge({
className?: string;
children: ReactNode;
}) {
return <UIBadge color={color} className={className}>{children}</UIBadge>;
return (
<UIBadge color={color} className={className}>
{children}
</UIBadge>
);
}
/* Form fields */

View File

@@ -0,0 +1,22 @@
import { Languages } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { changeLanguage } from '../../i18n';
import type { Language } from '../../i18n/language';
const OTHER: Record<Language, Language> = { pl: 'en', en: 'pl' };
export function LanguageToggle({ className = '' }: { className?: string }) {
const { t, i18n } = useTranslation();
const current: Language = i18n.language === 'en' ? 'en' : 'pl';
const next = OTHER[current];
return (
<button
onClick={() => changeLanguage(next)}
aria-label={`${t('common:toggleLanguage')} (${current.toUpperCase()} → ${next.toUpperCase()})`}
title={`${current.toUpperCase()} → ${next.toUpperCase()}`}
className={`inline-flex items-center justify-center p-2.5 rounded-[10px] bg-card border border-line text-dim shadow-card hover:text-ink hover:border-accent/45 cursor-pointer transition-all duration-150 ${className}`.trim()}
>
<Languages className="w-5 h-5" />
</button>
);
}

View File

@@ -1,13 +1,16 @@
import { Moon, Sun } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useTheme } from '../../store/theme';
export function ThemeToggle({ className = '' }: { className?: string }) {
const { theme, toggle } = useTheme();
const { t } = useTranslation();
const label = t('common:toggleTheme');
return (
<button
onClick={toggle}
aria-label="Przełącz motyw"
title="Przełącz motyw"
aria-label={label}
title={label}
className={`inline-flex items-center justify-center p-2.5 rounded-[10px] bg-card border border-line text-dim shadow-card hover:text-ink hover:border-accent/45 cursor-pointer transition-all duration-150 ${className}`.trim()}
>
{theme === 'dark' ? <Sun className="w-5 h-5" /> : <Moon className="w-5 h-5" />}