- 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>
34 lines
1.1 KiB
Dart
34 lines
1.1 KiB
Dart
import 'dart:ui';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import '../../core/config/app_constants.dart';
|
|
|
|
/// Langues prises en charge par l'application.
|
|
const List<Locale> supportedLocales = [Locale('en'), Locale('fr')];
|
|
|
|
/// Gère la langue sélectionnée, persistée dans les préférences.
|
|
class LocaleNotifier extends Notifier<Locale> {
|
|
@override
|
|
Locale build() {
|
|
_loadSaved();
|
|
return const Locale('en');
|
|
}
|
|
|
|
Future<void> _loadSaved() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final code = prefs.getString(AppConstants.prefsLocale);
|
|
if (code != null && supportedLocales.any((l) => l.languageCode == code)) {
|
|
state = Locale(code);
|
|
}
|
|
}
|
|
|
|
Future<void> setLocale(Locale locale) async {
|
|
state = locale;
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString(AppConstants.prefsLocale, locale.languageCode);
|
|
}
|
|
}
|
|
|
|
/// Langue active de l'application.
|
|
final localeProvider = NotifierProvider<LocaleNotifier, Locale>(LocaleNotifier.new);
|