- 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>
386 lines
11 KiB
Dart
386 lines
11 KiB
Dart
import 'dart:async';
|
||
|
||
import 'package:flutter/foundation.dart';
|
||
import 'package:flutter/widgets.dart';
|
||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||
import 'package:intl/intl.dart' as intl;
|
||
|
||
import 'app_localizations_en.dart';
|
||
import 'app_localizations_fr.dart';
|
||
|
||
// ignore_for_file: type=lint
|
||
|
||
/// Callers can lookup localized strings with an instance of AppLocalizations
|
||
/// returned by `AppLocalizations.of(context)`.
|
||
///
|
||
/// Applications need to include `AppLocalizations.delegate()` in their app's
|
||
/// `localizationDelegates` list, and the locales they support in the app's
|
||
/// `supportedLocales` list. For example:
|
||
///
|
||
/// ```dart
|
||
/// import 'l10n/app_localizations.dart';
|
||
///
|
||
/// return MaterialApp(
|
||
/// localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||
/// supportedLocales: AppLocalizations.supportedLocales,
|
||
/// home: MyApplicationHome(),
|
||
/// );
|
||
/// ```
|
||
///
|
||
/// ## Update pubspec.yaml
|
||
///
|
||
/// Please make sure to update your pubspec.yaml to include the following
|
||
/// packages:
|
||
///
|
||
/// ```yaml
|
||
/// dependencies:
|
||
/// # Internationalization support.
|
||
/// flutter_localizations:
|
||
/// sdk: flutter
|
||
/// intl: any # Use the pinned version from flutter_localizations
|
||
///
|
||
/// # Rest of dependencies
|
||
/// ```
|
||
///
|
||
/// ## iOS Applications
|
||
///
|
||
/// iOS applications define key application metadata, including supported
|
||
/// locales, in an Info.plist file that is built into the application bundle.
|
||
/// To configure the locales supported by your app, you’ll need to edit this
|
||
/// file.
|
||
///
|
||
/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file.
|
||
/// Then, in the Project Navigator, open the Info.plist file under the Runner
|
||
/// project’s Runner folder.
|
||
///
|
||
/// Next, select the Information Property List item, select Add Item from the
|
||
/// Editor menu, then select Localizations from the pop-up menu.
|
||
///
|
||
/// Select and expand the newly-created Localizations item then, for each
|
||
/// locale your application supports, add a new item and select the locale
|
||
/// you wish to add from the pop-up menu in the Value field. This list should
|
||
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
|
||
/// property.
|
||
abstract class AppLocalizations {
|
||
AppLocalizations(String locale)
|
||
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
|
||
|
||
final String localeName;
|
||
|
||
static AppLocalizations? of(BuildContext context) {
|
||
return Localizations.of<AppLocalizations>(context, AppLocalizations);
|
||
}
|
||
|
||
static const LocalizationsDelegate<AppLocalizations> delegate =
|
||
_AppLocalizationsDelegate();
|
||
|
||
/// A list of this localizations delegate along with the default localizations
|
||
/// delegates.
|
||
///
|
||
/// Returns a list of localizations delegates containing this delegate along with
|
||
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
|
||
/// and GlobalWidgetsLocalizations.delegate.
|
||
///
|
||
/// Additional delegates can be added by appending to this list in
|
||
/// MaterialApp. This list does not have to be used at all if a custom list
|
||
/// of delegates is preferred or required.
|
||
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
|
||
<LocalizationsDelegate<dynamic>>[
|
||
delegate,
|
||
GlobalMaterialLocalizations.delegate,
|
||
GlobalCupertinoLocalizations.delegate,
|
||
GlobalWidgetsLocalizations.delegate,
|
||
];
|
||
|
||
/// A list of this localizations delegate's supported locales.
|
||
static const List<Locale> supportedLocales = <Locale>[
|
||
Locale('en'),
|
||
Locale('fr')
|
||
];
|
||
|
||
/// No description provided for @appTitle.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'Pokéguess'**
|
||
String get appTitle;
|
||
|
||
/// No description provided for @whosThatPokemon.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'WHO\'S THAT POKÉMON?'**
|
||
String get whosThatPokemon;
|
||
|
||
/// No description provided for @shinyDetected.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'✨ SHINY POKÉMON DETECTED! ✨'**
|
||
String get shinyDetected;
|
||
|
||
/// No description provided for @genFilter.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'GEN FILTER'**
|
||
String get genFilter;
|
||
|
||
/// No description provided for @identificationInput.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'IDENTIFICATION INPUT'**
|
||
String get identificationInput;
|
||
|
||
/// No description provided for @hintPrefix.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'HINT'**
|
||
String get hintPrefix;
|
||
|
||
/// No description provided for @enterPokemonName.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'Enter Pokémon name...'**
|
||
String get enterPokemonName;
|
||
|
||
/// No description provided for @continueButton.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'CONTINUE'**
|
||
String get continueButton;
|
||
|
||
/// No description provided for @guessButton.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'GUESS!'**
|
||
String get guessButton;
|
||
|
||
/// No description provided for @hintButton.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'HINT ({count})'**
|
||
String hintButton(int count);
|
||
|
||
/// No description provided for @skipButton.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'SKIP ({count})'**
|
||
String skipButton(int count);
|
||
|
||
/// No description provided for @currentScore.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'CURRENT SCORE'**
|
||
String get currentScore;
|
||
|
||
/// No description provided for @personalBest.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'PERSONAL BEST: {score}'**
|
||
String personalBest(int score);
|
||
|
||
/// No description provided for @caughtShiny.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'✨ SHINY! You caught {name}! (+20 pts) ✨'**
|
||
String caughtShiny(String name);
|
||
|
||
/// No description provided for @caughtNormal.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'Correct! You caught {name}!'**
|
||
String caughtNormal(String name);
|
||
|
||
/// No description provided for @wrongGuess.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'Wrong guess! Try again.'**
|
||
String get wrongGuess;
|
||
|
||
/// No description provided for @errorLoadingPokemon.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'Error loading Pokémon'**
|
||
String get errorLoadingPokemon;
|
||
|
||
/// No description provided for @listNational.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'LIST - NATIONAL'**
|
||
String get listNational;
|
||
|
||
/// No description provided for @tabAll.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'ALL'**
|
||
String get tabAll;
|
||
|
||
/// No description provided for @tabCaught.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'CAUGHT'**
|
||
String get tabCaught;
|
||
|
||
/// No description provided for @pokemonDiscovered.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'POKEMON DISCOVERED'**
|
||
String get pokemonDiscovered;
|
||
|
||
/// No description provided for @noPokemonFound.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'NO POKEMON FOUND IN {filter}'**
|
||
String noPokemonFound(String filter);
|
||
|
||
/// No description provided for @pokedexFooter.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'NATIONAL POKEDEX V2.0'**
|
||
String get pokedexFooter;
|
||
|
||
/// No description provided for @loadingError.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'Loading error'**
|
||
String get loadingError;
|
||
|
||
/// No description provided for @baseStats.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'BASE STATS'**
|
||
String get baseStats;
|
||
|
||
/// No description provided for @noDescription.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'No description available for this Pokémon.'**
|
||
String get noDescription;
|
||
|
||
/// No description provided for @gameOver.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'GAME OVER'**
|
||
String get gameOver;
|
||
|
||
/// No description provided for @itWas.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'It was {name}!'**
|
||
String itWas(String name);
|
||
|
||
/// No description provided for @gameOverMessage.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'\"Looks like your journey ends here. You\'ve run out of energy!\"'**
|
||
String get gameOverMessage;
|
||
|
||
/// No description provided for @statStreak.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'STREAK'**
|
||
String get statStreak;
|
||
|
||
/// No description provided for @statSeen.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'SEEN'**
|
||
String get statSeen;
|
||
|
||
/// No description provided for @statScore.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'SCORE'**
|
||
String get statScore;
|
||
|
||
/// No description provided for @tryAgain.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'TRY AGAIN'**
|
||
String get tryAgain;
|
||
|
||
/// No description provided for @backToPokedex.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'BACK TO POKEDEX'**
|
||
String get backToPokedex;
|
||
|
||
/// No description provided for @system.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'SYSTEM'**
|
||
String get system;
|
||
|
||
/// No description provided for @statistics.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'STATISTICS'**
|
||
String get statistics;
|
||
|
||
/// No description provided for @colorPalette.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'COLOR PALETTE'**
|
||
String get colorPalette;
|
||
|
||
/// No description provided for @language.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'LANGUAGE'**
|
||
String get language;
|
||
|
||
/// No description provided for @statBestScore.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'Best score'**
|
||
String get statBestScore;
|
||
|
||
/// No description provided for @statCaught.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'Caught'**
|
||
String get statCaught;
|
||
|
||
/// No description provided for @statSeenLabel.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'Seen'**
|
||
String get statSeenLabel;
|
||
|
||
/// No description provided for @statCompletion.
|
||
///
|
||
/// In en, this message translates to:
|
||
/// **'Completion'**
|
||
String get statCompletion;
|
||
}
|
||
|
||
class _AppLocalizationsDelegate
|
||
extends LocalizationsDelegate<AppLocalizations> {
|
||
const _AppLocalizationsDelegate();
|
||
|
||
@override
|
||
Future<AppLocalizations> load(Locale locale) {
|
||
return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale));
|
||
}
|
||
|
||
@override
|
||
bool isSupported(Locale locale) =>
|
||
<String>['en', 'fr'].contains(locale.languageCode);
|
||
|
||
@override
|
||
bool shouldReload(_AppLocalizationsDelegate old) => false;
|
||
}
|
||
|
||
AppLocalizations lookupAppLocalizations(Locale locale) {
|
||
// Lookup logic when only language code is specified.
|
||
switch (locale.languageCode) {
|
||
case 'en':
|
||
return AppLocalizationsEn();
|
||
case 'fr':
|
||
return AppLocalizationsFr();
|
||
}
|
||
|
||
throw FlutterError(
|
||
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
|
||
'an issue with the localizations generation tool. Please file an issue '
|
||
'on GitHub with a reproducible sample app and the gen-l10n configuration '
|
||
'that was used.');
|
||
}
|