|
| 1 | +import 'dart:async'; |
| 2 | + |
| 3 | +import 'package:flutter/foundation.dart'; |
| 4 | +import 'package:flutter/widgets.dart'; |
| 5 | +import 'package:flutter_localizations/flutter_localizations.dart'; |
| 6 | +import 'package:intl/intl.dart' as intl; |
| 7 | + |
| 8 | +import 'app_localizations_en.dart'; |
| 9 | + |
| 10 | +// ignore_for_file: type=lint |
| 11 | + |
| 12 | +/// Callers can lookup localized strings with an instance of AppLocalizations |
| 13 | +/// returned by `AppLocalizations.of(context)`. |
| 14 | +/// |
| 15 | +/// Applications need to include `AppLocalizations.delegate()` in their app's |
| 16 | +/// `localizationDelegates` list, and the locales they support in the app's |
| 17 | +/// `supportedLocales` list. For example: |
| 18 | +/// |
| 19 | +/// ```dart |
| 20 | +/// import 'arb/app_localizations.dart'; |
| 21 | +/// |
| 22 | +/// return MaterialApp( |
| 23 | +/// localizationsDelegates: AppLocalizations.localizationsDelegates, |
| 24 | +/// supportedLocales: AppLocalizations.supportedLocales, |
| 25 | +/// home: MyApplicationHome(), |
| 26 | +/// ); |
| 27 | +/// ``` |
| 28 | +/// |
| 29 | +/// ## Update pubspec.yaml |
| 30 | +/// |
| 31 | +/// Please make sure to update your pubspec.yaml to include the following |
| 32 | +/// packages: |
| 33 | +/// |
| 34 | +/// ```yaml |
| 35 | +/// dependencies: |
| 36 | +/// # Internationalization support. |
| 37 | +/// flutter_localizations: |
| 38 | +/// sdk: flutter |
| 39 | +/// intl: any # Use the pinned version from flutter_localizations |
| 40 | +/// |
| 41 | +/// # Rest of dependencies |
| 42 | +/// ``` |
| 43 | +/// |
| 44 | +/// ## iOS Applications |
| 45 | +/// |
| 46 | +/// iOS applications define key application metadata, including supported |
| 47 | +/// locales, in an Info.plist file that is built into the application bundle. |
| 48 | +/// To configure the locales supported by your app, you’ll need to edit this |
| 49 | +/// file. |
| 50 | +/// |
| 51 | +/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file. |
| 52 | +/// Then, in the Project Navigator, open the Info.plist file under the Runner |
| 53 | +/// project’s Runner folder. |
| 54 | +/// |
| 55 | +/// Next, select the Information Property List item, select Add Item from the |
| 56 | +/// Editor menu, then select Localizations from the pop-up menu. |
| 57 | +/// |
| 58 | +/// Select and expand the newly-created Localizations item then, for each |
| 59 | +/// locale your application supports, add a new item and select the locale |
| 60 | +/// you wish to add from the pop-up menu in the Value field. This list should |
| 61 | +/// be consistent with the languages listed in the AppLocalizations.supportedLocales |
| 62 | +/// property. |
| 63 | +abstract class AppLocalizations { |
| 64 | + AppLocalizations(String locale) |
| 65 | + : localeName = intl.Intl.canonicalizedLocale(locale.toString()); |
| 66 | + |
| 67 | + final String localeName; |
| 68 | + |
| 69 | + static AppLocalizations? of(BuildContext context) { |
| 70 | + return Localizations.of<AppLocalizations>(context, AppLocalizations); |
| 71 | + } |
| 72 | + |
| 73 | + static const LocalizationsDelegate<AppLocalizations> delegate = |
| 74 | + _AppLocalizationsDelegate(); |
| 75 | + |
| 76 | + /// A list of this localizations delegate along with the default localizations |
| 77 | + /// delegates. |
| 78 | + /// |
| 79 | + /// Returns a list of localizations delegates containing this delegate along with |
| 80 | + /// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, |
| 81 | + /// and GlobalWidgetsLocalizations.delegate. |
| 82 | + /// |
| 83 | + /// Additional delegates can be added by appending to this list in |
| 84 | + /// MaterialApp. This list does not have to be used at all if a custom list |
| 85 | + /// of delegates is preferred or required. |
| 86 | + static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = |
| 87 | + <LocalizationsDelegate<dynamic>>[ |
| 88 | + delegate, |
| 89 | + GlobalMaterialLocalizations.delegate, |
| 90 | + GlobalCupertinoLocalizations.delegate, |
| 91 | + GlobalWidgetsLocalizations.delegate, |
| 92 | + ]; |
| 93 | + |
| 94 | + /// A list of this localizations delegate's supported locales. |
| 95 | + static const List<Locale> supportedLocales = <Locale>[Locale('en')]; |
| 96 | + |
| 97 | + /// App title |
| 98 | + /// |
| 99 | + /// In en, this message translates to: |
| 100 | + /// **'QuizApp'** |
| 101 | + String get appTitle; |
| 102 | + |
| 103 | + /// `AuthFailure` message |
| 104 | + /// |
| 105 | + /// In en, this message translates to: |
| 106 | + /// **'There\'s been an error, please log back in!'** |
| 107 | + String get authFailureMessage; |
| 108 | + |
| 109 | + /// `LogOutFailure` message |
| 110 | + /// |
| 111 | + /// In en, this message translates to: |
| 112 | + /// **'There\'s been an error while logging out, please try again!'** |
| 113 | + String get signOutFailureMessage; |
| 114 | + |
| 115 | + /// `AnonymousSignInFailure` message |
| 116 | + /// |
| 117 | + /// In en, this message translates to: |
| 118 | + /// **'You can\'t sign in as a guest at the moment, please try again later!'** |
| 119 | + String get anonymousSignInFailureMessage; |
| 120 | + |
| 121 | + /// `GoogleSignInFailure` message |
| 122 | + /// |
| 123 | + /// In en, this message translates to: |
| 124 | + /// **'There\'s been an error while signing in with google, please try again!'** |
| 125 | + String get googleSignInFailureMessage; |
| 126 | + |
| 127 | + /// `AppleSignInFailure` message |
| 128 | + /// |
| 129 | + /// In en, this message translates to: |
| 130 | + /// **'There\'s been an error while signing in with apple, please try again!'** |
| 131 | + String get appleSignInFailureMessage; |
| 132 | + |
| 133 | + /// `AppleSignInNotSupportedFailure` message |
| 134 | + /// |
| 135 | + /// In en, this message translates to: |
| 136 | + /// **'Apple sign in is not supported on your device!'** |
| 137 | + String get appleSignInNotSupportedFailureMessage; |
| 138 | + |
| 139 | + /// Unknown failure message |
| 140 | + /// |
| 141 | + /// In en, this message translates to: |
| 142 | + /// **'There\'s been an error, please try again!'** |
| 143 | + String get unknownFailureMessage; |
| 144 | + |
| 145 | + /// Sign in with google button label |
| 146 | + /// |
| 147 | + /// In en, this message translates to: |
| 148 | + /// **'Login to Start'** |
| 149 | + String get loginPreamble; |
| 150 | + |
| 151 | + /// `LoginPage` tagline |
| 152 | + /// |
| 153 | + /// In en, this message translates to: |
| 154 | + /// **'Test your app development knowledge with quick bite-sized quizzes from fireship.io'** |
| 155 | + String get loginTagline; |
| 156 | + |
| 157 | + /// No description provided for @loginWithGoogleButtonLabel. |
| 158 | + /// |
| 159 | + /// In en, this message translates to: |
| 160 | + /// **'Login with Google'** |
| 161 | + String get loginWithGoogleButtonLabel; |
| 162 | + |
| 163 | + /// Sign in with apple button label |
| 164 | + /// |
| 165 | + /// In en, this message translates to: |
| 166 | + /// **'Login with Apple'** |
| 167 | + String get loginWithAppleButtonLabel; |
| 168 | + |
| 169 | + /// Sign in as guest button label |
| 170 | + /// |
| 171 | + /// In en, this message translates to: |
| 172 | + /// **'Continue as Guest'** |
| 173 | + String get loginAsGuestButtonLabel; |
| 174 | + |
| 175 | + /// Topics label |
| 176 | + /// |
| 177 | + /// In en, this message translates to: |
| 178 | + /// **'Topics'** |
| 179 | + String get topicsLabel; |
| 180 | + |
| 181 | + /// About label |
| 182 | + /// |
| 183 | + /// In en, this message translates to: |
| 184 | + /// **'About'** |
| 185 | + String get aboutLabel; |
| 186 | + |
| 187 | + /// Profile label |
| 188 | + /// |
| 189 | + /// In en, this message translates to: |
| 190 | + /// **'Profile'** |
| 191 | + String get profileLabel; |
| 192 | + |
| 193 | + /// `GetTopicsFailure` message |
| 194 | + /// |
| 195 | + /// In en, this message translates to: |
| 196 | + /// **'There\'s been an error getting the topics 🙄'** |
| 197 | + String get getTopicsFailureMessage; |
| 198 | + |
| 199 | + /// No topics message |
| 200 | + /// |
| 201 | + /// In en, this message translates to: |
| 202 | + /// **'There are no topics 😏'** |
| 203 | + String get noTopicsMessage; |
| 204 | + |
| 205 | + /// Congrats message |
| 206 | + /// |
| 207 | + /// In en, this message translates to: |
| 208 | + /// **'Congrats! You completed the {quizTitle} quiz'** |
| 209 | + String congratsMessage(String quizTitle); |
| 210 | + |
| 211 | + /// `QuizStartButton` label |
| 212 | + /// |
| 213 | + /// In en, this message translates to: |
| 214 | + /// **'Start Quiz!'** |
| 215 | + String get quizStartButtonLabel; |
| 216 | + |
| 217 | + /// `CompleteQuizButton` label |
| 218 | + /// |
| 219 | + /// In en, this message translates to: |
| 220 | + /// **'Mark Complete!'** |
| 221 | + String get markQuizCompletedButtonLabel; |
| 222 | + |
| 223 | + /// Message shown when correctly answering a quiz question |
| 224 | + /// |
| 225 | + /// In en, this message translates to: |
| 226 | + /// **'Good Job!'** |
| 227 | + String get correctAnswerMessage; |
| 228 | + |
| 229 | + /// Message shown when incorrectly answering a quiz question |
| 230 | + /// |
| 231 | + /// In en, this message translates to: |
| 232 | + /// **'Wrong'** |
| 233 | + String get wrongAnswerMessage; |
| 234 | + |
| 235 | + /// `QuizButton`'s label on a correct answer |
| 236 | + /// |
| 237 | + /// In en, this message translates to: |
| 238 | + /// **'Onward!'** |
| 239 | + String get correctQuizButtonLabel; |
| 240 | + |
| 241 | + /// `QuizButton`'s label on an incorrect answer |
| 242 | + /// |
| 243 | + /// In en, this message translates to: |
| 244 | + /// **'Try Again'** |
| 245 | + String get wrongQuizButtonLabel; |
| 246 | + |
| 247 | + /// `QuizButton`'s label on an incorrect answer |
| 248 | + /// |
| 249 | + /// In en, this message translates to: |
| 250 | + /// **'There\'s no quiz data 😏'** |
| 251 | + String get noQuizDataMessage; |
| 252 | + |
| 253 | + /// `GetQuizFailure` message |
| 254 | + /// |
| 255 | + /// In en, this message translates to: |
| 256 | + /// **'There\'s been an error getting quiz data 🙄'** |
| 257 | + String get getQuizFailureMessage; |
| 258 | + |
| 259 | + /// Display name on guest profiles |
| 260 | + /// |
| 261 | + /// In en, this message translates to: |
| 262 | + /// **'Guest'** |
| 263 | + String get guestProfileDisplayName; |
| 264 | + |
| 265 | + /// Total completed quizzes label |
| 266 | + /// |
| 267 | + /// In en, this message translates to: |
| 268 | + /// **'Quizzes Completed'** |
| 269 | + String get totalCompletedQuizzesLabel; |
| 270 | + |
| 271 | + /// `LogOutButton`'s label on profile view |
| 272 | + /// |
| 273 | + /// In en, this message translates to: |
| 274 | + /// **'Logout'** |
| 275 | + String get logOutButtonLabel; |
| 276 | +} |
| 277 | + |
| 278 | +class _AppLocalizationsDelegate |
| 279 | + extends LocalizationsDelegate<AppLocalizations> { |
| 280 | + const _AppLocalizationsDelegate(); |
| 281 | + |
| 282 | + @override |
| 283 | + Future<AppLocalizations> load(Locale locale) { |
| 284 | + return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale)); |
| 285 | + } |
| 286 | + |
| 287 | + @override |
| 288 | + bool isSupported(Locale locale) => |
| 289 | + <String>['en'].contains(locale.languageCode); |
| 290 | + |
| 291 | + @override |
| 292 | + bool shouldReload(_AppLocalizationsDelegate old) => false; |
| 293 | +} |
| 294 | + |
| 295 | +AppLocalizations lookupAppLocalizations(Locale locale) { |
| 296 | + // Lookup logic when only language code is specified. |
| 297 | + switch (locale.languageCode) { |
| 298 | + case 'en': |
| 299 | + return AppLocalizationsEn(); |
| 300 | + } |
| 301 | + |
| 302 | + throw FlutterError( |
| 303 | + 'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely ' |
| 304 | + 'an issue with the localizations generation tool. Please file an issue ' |
| 305 | + 'on GitHub with a reproducible sample app and the gen-l10n configuration ' |
| 306 | + 'that was used.'); |
| 307 | +} |
0 commit comments