| 
 | 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_l10n_en.dart';  | 
 | 9 | +import 'app_l10n_zh.dart';  | 
 | 10 | + | 
 | 11 | +// ignore_for_file: type=lint  | 
 | 12 | + | 
 | 13 | +/// Callers can lookup localized strings with an instance of AppL10n  | 
 | 14 | +/// returned by `AppL10n.of(context)`.  | 
 | 15 | +///  | 
 | 16 | +/// Applications need to include `AppL10n.delegate()` in their app's  | 
 | 17 | +/// `localizationDelegates` list, and the locales they support in the app's  | 
 | 18 | +/// `supportedLocales` list. For example:  | 
 | 19 | +///  | 
 | 20 | +/// ```dart  | 
 | 21 | +/// import 'gen/app_l10n.dart';  | 
 | 22 | +///  | 
 | 23 | +/// return MaterialApp(  | 
 | 24 | +///   localizationsDelegates: AppL10n.localizationsDelegates,  | 
 | 25 | +///   supportedLocales: AppL10n.supportedLocales,  | 
 | 26 | +///   home: MyApplicationHome(),  | 
 | 27 | +/// );  | 
 | 28 | +/// ```  | 
 | 29 | +///  | 
 | 30 | +/// ## Update pubspec.yaml  | 
 | 31 | +///  | 
 | 32 | +/// Please make sure to update your pubspec.yaml to include the following  | 
 | 33 | +/// packages:  | 
 | 34 | +///  | 
 | 35 | +/// ```yaml  | 
 | 36 | +/// dependencies:  | 
 | 37 | +///   # Internationalization support.  | 
 | 38 | +///   flutter_localizations:  | 
 | 39 | +///     sdk: flutter  | 
 | 40 | +///   intl: any # Use the pinned version from flutter_localizations  | 
 | 41 | +///  | 
 | 42 | +///   # Rest of dependencies  | 
 | 43 | +/// ```  | 
 | 44 | +///  | 
 | 45 | +/// ## iOS Applications  | 
 | 46 | +///  | 
 | 47 | +/// iOS applications define key application metadata, including supported  | 
 | 48 | +/// locales, in an Info.plist file that is built into the application bundle.  | 
 | 49 | +/// To configure the locales supported by your app, you’ll need to edit this  | 
 | 50 | +/// file.  | 
 | 51 | +///  | 
 | 52 | +/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file.  | 
 | 53 | +/// Then, in the Project Navigator, open the Info.plist file under the Runner  | 
 | 54 | +/// project’s Runner folder.  | 
 | 55 | +///  | 
 | 56 | +/// Next, select the Information Property List item, select Add Item from the  | 
 | 57 | +/// Editor menu, then select Localizations from the pop-up menu.  | 
 | 58 | +///  | 
 | 59 | +/// Select and expand the newly-created Localizations item then, for each  | 
 | 60 | +/// locale your application supports, add a new item and select the locale  | 
 | 61 | +/// you wish to add from the pop-up menu in the Value field. This list should  | 
 | 62 | +/// be consistent with the languages listed in the AppL10n.supportedLocales  | 
 | 63 | +/// property.  | 
 | 64 | +abstract class AppL10n {  | 
 | 65 | +  AppL10n(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());  | 
 | 66 | + | 
 | 67 | +  final String localeName;  | 
 | 68 | + | 
 | 69 | +  static AppL10n of(BuildContext context) {  | 
 | 70 | +    return Localizations.of<AppL10n>(context, AppL10n)!;  | 
 | 71 | +  }  | 
 | 72 | + | 
 | 73 | +  static const LocalizationsDelegate<AppL10n> delegate = _AppL10nDelegate();  | 
 | 74 | + | 
 | 75 | +  /// A list of this localizations delegate along with the default localizations  | 
 | 76 | +  /// delegates.  | 
 | 77 | +  ///  | 
 | 78 | +  /// Returns a list of localizations delegates containing this delegate along with  | 
 | 79 | +  /// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,  | 
 | 80 | +  /// and GlobalWidgetsLocalizations.delegate.  | 
 | 81 | +  ///  | 
 | 82 | +  /// Additional delegates can be added by appending to this list in  | 
 | 83 | +  /// MaterialApp. This list does not have to be used at all if a custom list  | 
 | 84 | +  /// of delegates is preferred or required.  | 
 | 85 | +  static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[  | 
 | 86 | +    delegate,  | 
 | 87 | +    GlobalMaterialLocalizations.delegate,  | 
 | 88 | +    GlobalCupertinoLocalizations.delegate,  | 
 | 89 | +    GlobalWidgetsLocalizations.delegate,  | 
 | 90 | +  ];  | 
 | 91 | + | 
 | 92 | +  /// A list of this localizations delegate's supported locales.  | 
 | 93 | +  static const List<Locale> supportedLocales = <Locale>[  | 
 | 94 | +    Locale('en'),  | 
 | 95 | +    Locale('zh')  | 
 | 96 | +  ];  | 
 | 97 | + | 
 | 98 | +  /// No description provided for @deskTabWidgets.  | 
 | 99 | +  ///  | 
 | 100 | +  /// In zh, this message translates to:  | 
 | 101 | +  /// **'组件集录'**  | 
 | 102 | +  String get deskTabWidgets;  | 
 | 103 | + | 
 | 104 | +  /// No description provided for @deskTabPainter.  | 
 | 105 | +  ///  | 
 | 106 | +  /// In zh, this message translates to:  | 
 | 107 | +  /// **'绘制集录'**  | 
 | 108 | +  String get deskTabPainter;  | 
 | 109 | + | 
 | 110 | +  /// No description provided for @deskTabKnowledge.  | 
 | 111 | +  ///  | 
 | 112 | +  /// In zh, this message translates to:  | 
 | 113 | +  /// **'知识集锦'**  | 
 | 114 | +  String get deskTabKnowledge;  | 
 | 115 | + | 
 | 116 | +  /// No description provided for @deskTabTools.  | 
 | 117 | +  ///  | 
 | 118 | +  /// In zh, this message translates to:  | 
 | 119 | +  /// **'工具宝箱'**  | 
 | 120 | +  String get deskTabTools;  | 
 | 121 | + | 
 | 122 | +  /// No description provided for @deskTabMine.  | 
 | 123 | +  ///  | 
 | 124 | +  /// In zh, this message translates to:  | 
 | 125 | +  /// **'应用信息'**  | 
 | 126 | +  String get deskTabMine;  | 
 | 127 | + | 
 | 128 | +  /// No description provided for @mobileTabWidgets.  | 
 | 129 | +  ///  | 
 | 130 | +  /// In zh, this message translates to:  | 
 | 131 | +  /// **'组件'**  | 
 | 132 | +  String get mobileTabWidgets;  | 
 | 133 | + | 
 | 134 | +  /// No description provided for @mobileTabPainter.  | 
 | 135 | +  ///  | 
 | 136 | +  /// In zh, this message translates to:  | 
 | 137 | +  /// **'绘制'**  | 
 | 138 | +  String get mobileTabPainter;  | 
 | 139 | + | 
 | 140 | +  /// No description provided for @mobileTabKnowledge.  | 
 | 141 | +  ///  | 
 | 142 | +  /// In zh, this message translates to:  | 
 | 143 | +  /// **'知识'**  | 
 | 144 | +  String get mobileTabKnowledge;  | 
 | 145 | + | 
 | 146 | +  /// No description provided for @mobileTabTools.  | 
 | 147 | +  ///  | 
 | 148 | +  /// In zh, this message translates to:  | 
 | 149 | +  /// **'工具'**  | 
 | 150 | +  String get mobileTabTools;  | 
 | 151 | + | 
 | 152 | +  /// No description provided for @mobileTabMine.  | 
 | 153 | +  ///  | 
 | 154 | +  /// In zh, this message translates to:  | 
 | 155 | +  /// **'我的'**  | 
 | 156 | +  String get mobileTabMine;  | 
 | 157 | +}  | 
 | 158 | + | 
 | 159 | +class _AppL10nDelegate extends LocalizationsDelegate<AppL10n> {  | 
 | 160 | +  const _AppL10nDelegate();  | 
 | 161 | + | 
 | 162 | +  @override  | 
 | 163 | +  Future<AppL10n> load(Locale locale) {  | 
 | 164 | +    return SynchronousFuture<AppL10n>(lookupAppL10n(locale));  | 
 | 165 | +  }  | 
 | 166 | + | 
 | 167 | +  @override  | 
 | 168 | +  bool isSupported(Locale locale) => <String>['en', 'zh'].contains(locale.languageCode);  | 
 | 169 | + | 
 | 170 | +  @override  | 
 | 171 | +  bool shouldReload(_AppL10nDelegate old) => false;  | 
 | 172 | +}  | 
 | 173 | + | 
 | 174 | +AppL10n lookupAppL10n(Locale locale) {  | 
 | 175 | + | 
 | 176 | + | 
 | 177 | +  // Lookup logic when only language code is specified.  | 
 | 178 | +  switch (locale.languageCode) {  | 
 | 179 | +    case 'en': return AppL10nEn();  | 
 | 180 | +    case 'zh': return AppL10nZh();  | 
 | 181 | +  }  | 
 | 182 | + | 
 | 183 | +  throw FlutterError(  | 
 | 184 | +    'AppL10n.delegate failed to load unsupported locale "$locale". This is likely '  | 
 | 185 | +    'an issue with the localizations generation tool. Please file an issue '  | 
 | 186 | +    'on GitHub with a reproducible sample app and the gen-l10n configuration '  | 
 | 187 | +    'that was used.'  | 
 | 188 | +  );  | 
 | 189 | +}  | 
0 commit comments