|
| 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_de.dart'; |
| 9 | +import 'app_localizations_en.dart'; |
| 10 | +import 'app_localizations_pt.dart'; |
| 11 | + |
| 12 | +// ignore_for_file: type=lint |
| 13 | + |
| 14 | +/// Callers can lookup localized strings with an instance of AppLocalizations |
| 15 | +/// returned by `AppLocalizations.of(context)`. |
| 16 | +/// |
| 17 | +/// Applications need to include `AppLocalizations.delegate()` in their app's |
| 18 | +/// `localizationDelegates` list, and the locales they support in the app's |
| 19 | +/// `supportedLocales` list. For example: |
| 20 | +/// |
| 21 | +/// ```dart |
| 22 | +/// import 'l10n/app_localizations.dart'; |
| 23 | +/// |
| 24 | +/// return MaterialApp( |
| 25 | +/// localizationsDelegates: AppLocalizations.localizationsDelegates, |
| 26 | +/// supportedLocales: AppLocalizations.supportedLocales, |
| 27 | +/// home: MyApplicationHome(), |
| 28 | +/// ); |
| 29 | +/// ``` |
| 30 | +/// |
| 31 | +/// ## Update pubspec.yaml |
| 32 | +/// |
| 33 | +/// Please make sure to update your pubspec.yaml to include the following |
| 34 | +/// packages: |
| 35 | +/// |
| 36 | +/// ```yaml |
| 37 | +/// dependencies: |
| 38 | +/// # Internationalization support. |
| 39 | +/// flutter_localizations: |
| 40 | +/// sdk: flutter |
| 41 | +/// intl: any # Use the pinned version from flutter_localizations |
| 42 | +/// |
| 43 | +/// # Rest of dependencies |
| 44 | +/// ``` |
| 45 | +/// |
| 46 | +/// ## iOS Applications |
| 47 | +/// |
| 48 | +/// iOS applications define key application metadata, including supported |
| 49 | +/// locales, in an Info.plist file that is built into the application bundle. |
| 50 | +/// To configure the locales supported by your app, you’ll need to edit this |
| 51 | +/// file. |
| 52 | +/// |
| 53 | +/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file. |
| 54 | +/// Then, in the Project Navigator, open the Info.plist file under the Runner |
| 55 | +/// project’s Runner folder. |
| 56 | +/// |
| 57 | +/// Next, select the Information Property List item, select Add Item from the |
| 58 | +/// Editor menu, then select Localizations from the pop-up menu. |
| 59 | +/// |
| 60 | +/// Select and expand the newly-created Localizations item then, for each |
| 61 | +/// locale your application supports, add a new item and select the locale |
| 62 | +/// you wish to add from the pop-up menu in the Value field. This list should |
| 63 | +/// be consistent with the languages listed in the AppLocalizations.supportedLocales |
| 64 | +/// property. |
| 65 | +abstract class AppLocalizations { |
| 66 | + AppLocalizations(String locale) |
| 67 | + : localeName = intl.Intl.canonicalizedLocale(locale.toString()); |
| 68 | + |
| 69 | + final String localeName; |
| 70 | + |
| 71 | + static AppLocalizations? of(BuildContext context) { |
| 72 | + return Localizations.of<AppLocalizations>(context, AppLocalizations); |
| 73 | + } |
| 74 | + |
| 75 | + static const LocalizationsDelegate<AppLocalizations> delegate = |
| 76 | + _AppLocalizationsDelegate(); |
| 77 | + |
| 78 | + /// A list of this localizations delegate along with the default localizations |
| 79 | + /// delegates. |
| 80 | + /// |
| 81 | + /// Returns a list of localizations delegates containing this delegate along with |
| 82 | + /// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, |
| 83 | + /// and GlobalWidgetsLocalizations.delegate. |
| 84 | + /// |
| 85 | + /// Additional delegates can be added by appending to this list in |
| 86 | + /// MaterialApp. This list does not have to be used at all if a custom list |
| 87 | + /// of delegates is preferred or required. |
| 88 | + static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = |
| 89 | + <LocalizationsDelegate<dynamic>>[ |
| 90 | + delegate, |
| 91 | + GlobalMaterialLocalizations.delegate, |
| 92 | + GlobalCupertinoLocalizations.delegate, |
| 93 | + GlobalWidgetsLocalizations.delegate, |
| 94 | + ]; |
| 95 | + |
| 96 | + /// A list of this localizations delegate's supported locales. |
| 97 | + static const List<Locale> supportedLocales = <Locale>[ |
| 98 | + Locale('de'), |
| 99 | + Locale('en'), |
| 100 | + Locale('pt') |
| 101 | + ]; |
| 102 | + |
| 103 | + /// The title of the application |
| 104 | + /// |
| 105 | + /// In en, this message translates to: |
| 106 | + /// **'flutter_bloc_app_template'** |
| 107 | + String get appTitle; |
| 108 | + |
| 109 | + /// The title of the sample items |
| 110 | + /// |
| 111 | + /// In en, this message translates to: |
| 112 | + /// **'Sample Items'** |
| 113 | + String get itemsTitle; |
| 114 | + |
| 115 | + /// The title of the emails screen |
| 116 | + /// |
| 117 | + /// In en, this message translates to: |
| 118 | + /// **'Emails'** |
| 119 | + String get emailsTitle; |
| 120 | + |
| 121 | + /// The title of the launches screen |
| 122 | + /// |
| 123 | + /// In en, this message translates to: |
| 124 | + /// **'Launches'** |
| 125 | + String get launchesTitle; |
| 126 | + |
| 127 | + /// The title of the item |
| 128 | + /// |
| 129 | + /// In en, this message translates to: |
| 130 | + /// **'Sample Item {id}'** |
| 131 | + String itemTitle(Object id); |
| 132 | + |
| 133 | + /// The title of the settings |
| 134 | + /// |
| 135 | + /// In en, this message translates to: |
| 136 | + /// **'Settings'** |
| 137 | + String get settingsTitle; |
| 138 | + |
| 139 | + /// The mission launch item label |
| 140 | + /// |
| 141 | + /// In en, this message translates to: |
| 142 | + /// **'Mission: {mission}'** |
| 143 | + String missionTitle(Object mission); |
| 144 | + |
| 145 | + /// Launched at item label |
| 146 | + /// |
| 147 | + /// In en, this message translates to: |
| 148 | + /// **'Launched at: {launchedAt}'** |
| 149 | + String launchedAt(Object launchedAt); |
| 150 | + |
| 151 | + /// Rocket item label |
| 152 | + /// |
| 153 | + /// In en, this message translates to: |
| 154 | + /// **'Rocket: {rocketName} ({rocketType})'** |
| 155 | + String rocket(Object rocketName, Object rocketType); |
| 156 | + |
| 157 | + /// Shows how many days ago from today |
| 158 | + /// |
| 159 | + /// In en, this message translates to: |
| 160 | + /// **'{days} days ago'** |
| 161 | + String daysSinceTodayTitle(Object days); |
| 162 | + |
| 163 | + /// Shows how many days from today |
| 164 | + /// |
| 165 | + /// In en, this message translates to: |
| 166 | + /// **'In {days} days'** |
| 167 | + String daysFromTodayTitle(Object days); |
| 168 | + |
| 169 | + /// No description provided for @themeTitle. |
| 170 | + /// |
| 171 | + /// In en, this message translates to: |
| 172 | + /// **'Theme'** |
| 173 | + String get themeTitle; |
| 174 | + |
| 175 | + /// No description provided for @systemThemeTitle. |
| 176 | + /// |
| 177 | + /// In en, this message translates to: |
| 178 | + /// **'System Theme'** |
| 179 | + String get systemThemeTitle; |
| 180 | + |
| 181 | + /// No description provided for @lightThemeTitle. |
| 182 | + /// |
| 183 | + /// In en, this message translates to: |
| 184 | + /// **'Light Theme'** |
| 185 | + String get lightThemeTitle; |
| 186 | + |
| 187 | + /// No description provided for @darkThemeTitle. |
| 188 | + /// |
| 189 | + /// In en, this message translates to: |
| 190 | + /// **'Dark Theme'** |
| 191 | + String get darkThemeTitle; |
| 192 | + |
| 193 | + /// No description provided for @lightGoldThemeTitle. |
| 194 | + /// |
| 195 | + /// In en, this message translates to: |
| 196 | + /// **'Light Gold'** |
| 197 | + String get lightGoldThemeTitle; |
| 198 | + |
| 199 | + /// No description provided for @darkGoldThemeTitle. |
| 200 | + /// |
| 201 | + /// In en, this message translates to: |
| 202 | + /// **'Dark Gold'** |
| 203 | + String get darkGoldThemeTitle; |
| 204 | + |
| 205 | + /// No description provided for @lightMintThemeTitle. |
| 206 | + /// |
| 207 | + /// In en, this message translates to: |
| 208 | + /// **'Light Mint'** |
| 209 | + String get lightMintThemeTitle; |
| 210 | + |
| 211 | + /// No description provided for @darkMintThemeTitle. |
| 212 | + /// |
| 213 | + /// In en, this message translates to: |
| 214 | + /// **'Dark Mint'** |
| 215 | + String get darkMintThemeTitle; |
| 216 | + |
| 217 | + /// No description provided for @experimentalThemeTitle. |
| 218 | + /// |
| 219 | + /// In en, this message translates to: |
| 220 | + /// **'Experimental Theme'** |
| 221 | + String get experimentalThemeTitle; |
| 222 | + |
| 223 | + /// The title of the Item Details screen |
| 224 | + /// |
| 225 | + /// In en, this message translates to: |
| 226 | + /// **'Item Details'** |
| 227 | + String get itemDetailsTitle; |
| 228 | + |
| 229 | + /// No description provided for @error. |
| 230 | + /// |
| 231 | + /// In en, this message translates to: |
| 232 | + /// **'Error'** |
| 233 | + String get error; |
| 234 | + |
| 235 | + /// No description provided for @emptyList. |
| 236 | + /// |
| 237 | + /// In en, this message translates to: |
| 238 | + /// **'Empty list'** |
| 239 | + String get emptyList; |
| 240 | + |
| 241 | + /// No description provided for @tabHome. |
| 242 | + /// |
| 243 | + /// In en, this message translates to: |
| 244 | + /// **'Home'** |
| 245 | + String get tabHome; |
| 246 | + |
| 247 | + /// No description provided for @tabSettings. |
| 248 | + /// |
| 249 | + /// In en, this message translates to: |
| 250 | + /// **'Settings'** |
| 251 | + String get tabSettings; |
| 252 | + |
| 253 | + /// No description provided for @newsScreen. |
| 254 | + /// |
| 255 | + /// In en, this message translates to: |
| 256 | + /// **'News'** |
| 257 | + String get newsScreen; |
| 258 | + |
| 259 | + /// No description provided for @disabledButtonTitle. |
| 260 | + /// |
| 261 | + /// In en, this message translates to: |
| 262 | + /// **'Disabled'** |
| 263 | + String get disabledButtonTitle; |
| 264 | + |
| 265 | + /// No description provided for @disabledRoundedButtonTitle. |
| 266 | + /// |
| 267 | + /// In en, this message translates to: |
| 268 | + /// **'Disabled Rounded'** |
| 269 | + String get disabledRoundedButtonTitle; |
| 270 | + |
| 271 | + /// No description provided for @disabledWithIconButtonTitle. |
| 272 | + /// |
| 273 | + /// In en, this message translates to: |
| 274 | + /// **'Disabled With Icon'** |
| 275 | + String get disabledWithIconButtonTitle; |
| 276 | + |
| 277 | + /// No description provided for @enabledButtonTitle. |
| 278 | + /// |
| 279 | + /// In en, this message translates to: |
| 280 | + /// **'Enabled'** |
| 281 | + String get enabledButtonTitle; |
| 282 | + |
| 283 | + /// No description provided for @borderRadiusButtonTitle. |
| 284 | + /// |
| 285 | + /// In en, this message translates to: |
| 286 | + /// **'BorderRadius'** |
| 287 | + String get borderRadiusButtonTitle; |
| 288 | + |
| 289 | + /// No description provided for @borderSideButtonTitle. |
| 290 | + /// |
| 291 | + /// In en, this message translates to: |
| 292 | + /// **'BorderSide'** |
| 293 | + String get borderSideButtonTitle; |
| 294 | + |
| 295 | + /// No description provided for @iconButtonTitle. |
| 296 | + /// |
| 297 | + /// In en, this message translates to: |
| 298 | + /// **'With Icon'** |
| 299 | + String get iconButtonTitle; |
| 300 | + |
| 301 | + /// No description provided for @iconAndPaddingButtonTitle. |
| 302 | + /// |
| 303 | + /// In en, this message translates to: |
| 304 | + /// **'With Icon Padding'** |
| 305 | + String get iconAndPaddingButtonTitle; |
| 306 | + |
| 307 | + /// No description provided for @transparentButtonTitle. |
| 308 | + /// |
| 309 | + /// In en, this message translates to: |
| 310 | + /// **'Transparent'** |
| 311 | + String get transparentButtonTitle; |
| 312 | +} |
| 313 | + |
| 314 | +class _AppLocalizationsDelegate |
| 315 | + extends LocalizationsDelegate<AppLocalizations> { |
| 316 | + const _AppLocalizationsDelegate(); |
| 317 | + |
| 318 | + @override |
| 319 | + Future<AppLocalizations> load(Locale locale) { |
| 320 | + return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale)); |
| 321 | + } |
| 322 | + |
| 323 | + @override |
| 324 | + bool isSupported(Locale locale) => |
| 325 | + <String>['de', 'en', 'pt'].contains(locale.languageCode); |
| 326 | + |
| 327 | + @override |
| 328 | + bool shouldReload(_AppLocalizationsDelegate old) => false; |
| 329 | +} |
| 330 | + |
| 331 | +AppLocalizations lookupAppLocalizations(Locale locale) { |
| 332 | + // Lookup logic when only language code is specified. |
| 333 | + switch (locale.languageCode) { |
| 334 | + case 'de': |
| 335 | + return AppLocalizationsDe(); |
| 336 | + case 'en': |
| 337 | + return AppLocalizationsEn(); |
| 338 | + case 'pt': |
| 339 | + return AppLocalizationsPt(); |
| 340 | + } |
| 341 | + |
| 342 | + throw FlutterError( |
| 343 | + 'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely ' |
| 344 | + 'an issue with the localizations generation tool. Please file an issue ' |
| 345 | + 'on GitHub with a reproducible sample app and the gen-l10n configuration ' |
| 346 | + 'that was used.'); |
| 347 | +} |
0 commit comments