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>
This commit is contained in:
2026-06-23 12:13:51 +02:00
co-authored by Claude Opus 4.8
parent 409ab9c1dd
commit a2a7ffd79f
26 changed files with 1012 additions and 70 deletions
+4 -3
View File
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/config/app_constants.dart';
import '../../l10n/app_localizations.dart';
import '../providers/repository_provider.dart';
import '../widgets/game_over/game_over_header.dart';
import '../widgets/game_over/game_over_stats.dart';
@@ -70,10 +71,10 @@ class _GameOverPageState extends ConsumerState<GameOverPage> {
width: double.infinity,
color: messageBoxBg,
padding: const EdgeInsets.all(24),
child: const Text(
"\"Looks like your journey\nends here. You've run out\nof energy!\"",
child: Text(
AppLocalizations.of(context)!.gameOverMessage,
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white, fontSize: 18, height: 1.5),
style: const TextStyle(color: Colors.white, fontSize: 18, height: 1.5),
),
),
const SizedBox(height: 16),
+7 -6
View File
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../domain/game/game_state.dart';
import '../../l10n/app_localizations.dart';
import '../providers/gen_filter_provider.dart';
import '../providers/game_provider.dart';
import '../providers/navigation_provider.dart';
@@ -44,19 +45,19 @@ class _GuessPageState extends ConsumerState<GuessPage> {
Future<void> _onGuess() async {
final result = await ref.read(gameProvider.notifier).submitGuess(_guessController.text);
if (!mounted) return;
final l = AppLocalizations.of(context)!;
final state = ref.read(gameProvider);
switch (result) {
case GuessResult.correct:
final name = state.currentPokemon!.formatedName;
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(state.isShiny
? '✨ SHINY! You caught ${state.currentPokemon!.formatedName}! (+20 pts) ✨'
: 'Correct! You caught ${state.currentPokemon!.formatedName}!'),
content: Text(state.isShiny ? l.caughtShiny(name) : l.caughtNormal(name)),
backgroundColor: state.isShiny ? Colors.amber[800] : Colors.green,
));
break;
case GuessResult.wrong:
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Wrong guess! Try again.'), backgroundColor: Colors.orange));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(l.wrongGuess), backgroundColor: Colors.orange));
break;
case GuessResult.gameOver:
await _showGameOver();
@@ -96,7 +97,7 @@ class _GuessPageState extends ConsumerState<GuessPage> {
return const Center(child: CircularProgressIndicator());
}
if (state.currentPokemon == null || state.status == GameStatus.error) {
return const Center(child: Text("Error loading Pokémon"));
return Center(child: Text(AppLocalizations.of(context)!.errorLoadingPokemon));
}
final pokemon = state.currentPokemon!;
+14 -10
View File
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../domain/entities/pokemon.dart';
import '../../l10n/app_localizations.dart';
import '../providers/pokedex_provider.dart';
import '../widgets/pokemon_tile.dart';
import '../widgets/scanline_overlay.dart';
@@ -32,6 +33,7 @@ class _PokemonListPageState extends ConsumerState<PokemonListPage> {
@override
Widget build(BuildContext context) {
final l = AppLocalizations.of(context)!;
final pokedexAsync = ref.watch(pokedexProvider);
final caughtCount = ref.watch(caughtCountProvider);
@@ -45,8 +47,8 @@ class _PokemonListPageState extends ConsumerState<PokemonListPage> {
height: 40,
child: Row(
children: [
_buildTab('ALL', _filter == 'ALL'),
_buildTab('CAUGHT', _filter == 'CAUGHT'),
_buildTab('ALL', l.tabAll, _filter == 'ALL'),
_buildTab('CAUGHT', l.tabCaught, _filter == 'CAUGHT'),
],
),
),
@@ -58,7 +60,7 @@ class _PokemonListPageState extends ConsumerState<PokemonListPage> {
pokedexAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (e, _) => Center(
child: Text('Erreur de chargement\n$e',
child: Text('${l.loadingError}\n$e',
textAlign: TextAlign.center, style: const TextStyle(color: Colors.black54)),
),
data: (all) {
@@ -79,8 +81,8 @@ class _PokemonListPageState extends ConsumerState<PokemonListPage> {
height: 24,
color: const Color(0xFF1B2333),
alignment: Alignment.center,
child: const Text('NATIONAL POKEDEX V2.0',
style: TextStyle(color: Colors.white70, fontSize: 12, letterSpacing: 1)),
child: Text(l.pokedexFooter,
style: const TextStyle(color: Colors.white70, fontSize: 12, letterSpacing: 1)),
),
],
),
@@ -88,25 +90,27 @@ class _PokemonListPageState extends ConsumerState<PokemonListPage> {
}
Widget _emptyState() {
final l = AppLocalizations.of(context)!;
final filterLabel = _filter == 'CAUGHT' ? l.tabCaught : l.tabAll;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.search_off, size: 64, color: Colors.black26),
const SizedBox(height: 16),
Text('NO POKEMON FOUND IN $_filter',
Text(l.noPokemonFound(filterLabel),
style: const TextStyle(color: Colors.black45, fontSize: 18, fontWeight: FontWeight.bold)),
],
),
);
}
Widget _buildTab(String title, bool isSelected) {
Widget _buildTab(String key, String label, bool isSelected) {
return Expanded(
child: GestureDetector(
onTap: () {
if (_filter != title) {
setState(() => _filter = title);
if (_filter != key) {
setState(() => _filter = key);
if (_scrollController.hasClients) _scrollController.jumpTo(0);
}
},
@@ -118,7 +122,7 @@ class _PokemonListPageState extends ConsumerState<PokemonListPage> {
: null,
),
alignment: Alignment.center,
child: Text(title,
child: Text(label,
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: isSelected ? Colors.black : Colors.black54)),
),
+21 -9
View File
@@ -2,14 +2,17 @@ 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 et sélection de la palette de couleurs.
/// Page "Système" : statistiques de jeu, langue et palette de couleurs.
class SystemPage extends ConsumerWidget {
const SystemPage({super.key});
@@ -20,6 +23,7 @@ class SystemPage extends ConsumerWidget {
@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);
@@ -28,18 +32,18 @@ class SystemPage extends ConsumerWidget {
color: const Color(0xFFC8D1D8),
child: Column(
children: [
SystemHeader(primaryColor: palette.primary),
SystemHeader(primaryColor: palette.primary, title: l.system),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SectionTitle(text: 'STATISTIQUES', color: palette.primary),
SectionTitle(text: l.statistics, color: palette.primary),
const SizedBox(height: 8),
pokedexAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (_, __) => const Text('Erreur de chargement'),
error: (_, __) => Text(l.loadingError),
data: (pokemons) {
final total = pokemons.length;
final caught = pokemons.where((p) => p.isCaught).length;
@@ -52,10 +56,10 @@ class SystemPage extends ConsumerWidget {
return StatsGrid(
primaryColor: palette.primary,
items: [
StatItem(label: 'Meilleur score', value: '$best', icon: Icons.emoji_events),
StatItem(label: 'Attrapés', value: '$caught / $total', icon: Icons.catching_pokemon),
StatItem(label: 'Vus', value: '$seen / $total', icon: Icons.visibility),
StatItem(label: 'Complétion', value: '$pct%', icon: Icons.pie_chart),
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),
],
);
},
@@ -63,7 +67,15 @@ class SystemPage extends ConsumerWidget {
},
),
const SizedBox(height: 24),
SectionTitle(text: 'PALETTE DE COULEURS', color: palette.primary),
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,