Add translations support

This commit is contained in:
Alex Gleason committed 2025-09-19 13:40:11 -05:00
1 parent dd970c2ca7
commit ced204bfde
15 files changed
+444 -31

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { TestApp } from '@/test/TestApp';
import { Preferences } from './Preferences';
describe('Preferences', () => {
it('renders preferences page with language and theme sections', () => {
render(
<TestApp>
<Preferences />
</TestApp>
);
// Should show the preferences title
expect(screen.getByText('Preferences')).toBeInTheDocument();
// Should show appearance section
expect(screen.getByText('Appearance')).toBeInTheDocument();
// Should show theme and language labels
expect(screen.getByText('Theme')).toBeInTheDocument();
expect(screen.getByText('Language')).toBeInTheDocument();
// Should show language picker
expect(screen.getByRole('combobox')).toBeInTheDocument();
});
it('displays translated content correctly', () => {
render(
<TestApp>
<Preferences />
</TestApp>
);
// Check for key translated strings
expect(screen.getByText('Manage your general application preferences and appearance settings.')).toBeInTheDocument();
expect(screen.getByText('Customize how the application looks and feels.')).toBeInTheDocument();
expect(screen.getByText('Select your preferred language for the interface.')).toBeInTheDocument();
});
});
+23 -10
View File
@@ -1,12 +1,15 @@
import { Settings2, ArrowLeft } from "lucide-react";
import { useTranslation } from 'react-i18next';
import { Button } from "@/components/ui/button";
import { ThemePicker } from "@/components/ThemePicker";
import { LanguagePicker } from "@/components/LanguagePicker";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Label } from "@/components/ui/label";
import { useIsMobile } from "@/hooks/useIsMobile";
import { useNavigate } from "react-router-dom";
export function Preferences() {
const { t } = useTranslation();
const isMobile = useIsMobile();
const navigate = useNavigate();
@@ -21,15 +24,15 @@ export function Preferences() {
className="h-8 w-auto px-2 -ml-2"
>
<ArrowLeft className="h-4 w-4 mr-2" />
Back to Settings
{t('backToSettings')}
</Button>
<div className="space-y-2">
<h1 className="text-2xl font-bold flex items-center gap-3">
<Settings2 className="h-6 w-6 text-primary" />
Preferences
{t('preferencesTitle')}
</h1>
<p className="text-muted-foreground">
Manage your general application preferences and appearance settings.
{t('preferencesDescription')}
</p>
</div>
</div>
@@ -39,29 +42,39 @@ export function Preferences() {
<div className="space-y-2">
<h1 className="text-2xl font-bold flex items-center gap-3">
<Settings2 className="h-6 w-6 text-primary" />
Preferences
{t('preferencesTitle')}
</h1>
<p className="text-muted-foreground">
Manage your general application preferences and appearance settings.
{t('preferencesDescription')}
</p>
</div>
)}
<Card>
<CardHeader>
<CardTitle>Appearance</CardTitle>
<CardTitle>{t('appearance')}</CardTitle>
<CardDescription>
Customize how the application looks and feels.
{t('appearanceDescription')}
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<CardContent className="space-y-6">
<div className="space-y-2">
<Label htmlFor="theme-picker">Theme</Label>
<Label htmlFor="theme-picker">{t('theme')}</Label>
<div className="w-full max-w-xs">
<ThemePicker />
</div>
<p className="text-sm text-muted-foreground">
Choose between light, dark, or system theme preference.
{t('themeDescription')}
</p>
</div>
<div className="space-y-2">
<Label htmlFor="language-picker">{t('language')}</Label>
<div className="w-full max-w-xs">
<LanguagePicker />
</div>
<p className="text-sm text-muted-foreground">
{t('languageDescription')}
</p>
</div>
</CardContent>
+18 -13
View File
@@ -1,4 +1,5 @@
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { Bot, GitBranch, Database, Wifi, Settings2 } from 'lucide-react';
import { useIsMobile } from '@/hooks/useIsMobile';
@@ -10,55 +11,59 @@ interface SettingsItem {
href: string;
}
const settingsItems: SettingsItem[] = [
// Define settings items as a function to get fresh translations
const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [
{
id: 'preferences',
title: 'Preferences',
description: 'General application preferences and appearance',
title: t('preferences'),
description: t('preferencesDescription'),
icon: Settings2,
href: '/settings/preferences',
},
{
id: 'ai',
title: 'AI Settings',
description: 'Configure AI providers and API keys',
title: t('aiSettings'),
description: t('aiSettingsDescription'),
icon: Bot,
href: '/settings/ai',
},
{
id: 'git',
title: 'Git Settings',
description: 'Configure Git credentials for HTTP authentication',
title: t('gitSettings'),
description: t('gitSettingsDescription'),
icon: GitBranch,
href: '/settings/git',
},
{
id: 'nostr',
title: 'Nostr Settings',
description: 'Configure relay connections and Nostr preferences',
title: t('nostrSettings'),
description: t('nostrSettingsDescription'),
icon: Wifi,
href: '/settings/nostr',
},
{
id: 'data',
title: 'Data',
description: 'Export files and manage local data',
title: t('dataSettings'),
description: t('dataSettingsDescription'),
icon: Database,
href: '/settings/data',
},
];
export function Settings() {
const { t } = useTranslation();
const navigate = useNavigate();
const isMobile = useIsMobile();
const settingsItems = getSettingsItems(t);
if (isMobile) {
return (
<div className="p-6 space-y-4">
<div className="space-y-2">
<h2 className="text-xl font-bold">Settings</h2>
<h2 className="text-xl font-bold">{t('settingsTitle')}</h2>
<p className="text-muted-foreground">
Manage your application settings and preferences.
{t('settingsDescription')}
</p>
</div>
<div className="space-y-3">