Maxiwere45 a2a7ffd79f feat(i18n): add FR/EN internationalization with in-app language selector
- gen-l10n setup (flutter_localizations, intl, l10n.yaml, ARB en/fr)
- localeProvider (persisted) wired into MaterialApp
- language selector in the System page (alongside the color palette)
- all user-facing strings across screens moved to AppLocalizations

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 12:13:51 +02:00

93 lines
4.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../core/config/app_constants.dart';
import '../../l10n/app_localizations.dart';
import '../providers/pokedex_provider.dart';
import '../providers/theme_provider.dart';
import '../providers/locale_provider.dart';
import '../widgets/system/system_header.dart';
import '../widgets/system/section_title.dart';
import '../widgets/system/system_stats.dart';
import '../widgets/system/palette_picker.dart';
import '../widgets/system/language_picker.dart';
/// Page "Système" : statistiques de jeu, langue et palette de couleurs.
class SystemPage extends ConsumerWidget {
const SystemPage({super.key});
Future<int> _loadBestScore() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getInt(AppConstants.prefsBestScore) ?? 0;
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final l = AppLocalizations.of(context)!;
final paletteIndex = ref.watch(themeProvider);
final palette = appPalettes[paletteIndex];
final pokedexAsync = ref.watch(pokedexProvider);
return Container(
color: const Color(0xFFC8D1D8),
child: Column(
children: [
SystemHeader(primaryColor: palette.primary, title: l.system),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SectionTitle(text: l.statistics, color: palette.primary),
const SizedBox(height: 8),
pokedexAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (_, __) => Text(l.loadingError),
data: (pokemons) {
final total = pokemons.length;
final caught = pokemons.where((p) => p.isCaught).length;
final seen = pokemons.where((p) => p.isSeen).length;
final pct = total > 0 ? (caught / total * 100).toStringAsFixed(1) : '0.0';
return FutureBuilder<int>(
future: _loadBestScore(),
builder: (context, snap) {
final best = snap.data ?? 0;
return StatsGrid(
primaryColor: palette.primary,
items: [
StatItem(label: l.statBestScore, value: '$best', icon: Icons.emoji_events),
StatItem(label: l.statCaught, value: '$caught / $total', icon: Icons.catching_pokemon),
StatItem(label: l.statSeenLabel, value: '$seen / $total', icon: Icons.visibility),
StatItem(label: l.statCompletion, value: '$pct%', icon: Icons.pie_chart),
],
);
},
);
},
),
const SizedBox(height: 24),
SectionTitle(text: l.language, color: palette.primary),
const SizedBox(height: 8),
LanguagePicker(
selected: ref.watch(localeProvider),
primaryColor: palette.primary,
onSelect: (loc) => ref.read(localeProvider.notifier).setLocale(loc),
),
const SizedBox(height: 24),
SectionTitle(text: l.colorPalette, color: palette.primary),
const SizedBox(height: 8),
PalettePicker(
selectedIndex: paletteIndex,
onSelect: (i) => ref.read(themeProvider.notifier).setPalette(i),
),
],
),
),
),
],
),
);
}
}