|
| 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 'messages_ar.dart'; |
| 9 | +import 'messages_bn.dart'; |
| 10 | +import 'messages_bs.dart'; |
| 11 | +import 'messages_ca.dart'; |
| 12 | +import 'messages_cs.dart'; |
| 13 | +import 'messages_da.dart'; |
| 14 | +import 'messages_de.dart'; |
| 15 | +import 'messages_el.dart'; |
| 16 | +import 'messages_en.dart'; |
| 17 | +import 'messages_es.dart'; |
| 18 | +import 'messages_et.dart'; |
| 19 | +import 'messages_fa.dart'; |
| 20 | +import 'messages_fi.dart'; |
| 21 | +import 'messages_fr.dart'; |
| 22 | +import 'messages_he.dart'; |
| 23 | +import 'messages_hr.dart'; |
| 24 | +import 'messages_hu.dart'; |
| 25 | +import 'messages_id.dart'; |
| 26 | +import 'messages_it.dart'; |
| 27 | +import 'messages_ja.dart'; |
| 28 | +import 'messages_ko.dart'; |
| 29 | +import 'messages_lo.dart'; |
| 30 | +import 'messages_mn.dart'; |
| 31 | +import 'messages_ms.dart'; |
| 32 | +import 'messages_ne.dart'; |
| 33 | +import 'messages_nl.dart'; |
| 34 | +import 'messages_no.dart'; |
| 35 | +import 'messages_pl.dart'; |
| 36 | +import 'messages_pt.dart'; |
| 37 | +import 'messages_ro.dart'; |
| 38 | +import 'messages_ru.dart'; |
| 39 | +import 'messages_se.dart'; |
| 40 | +import 'messages_sk.dart'; |
| 41 | +import 'messages_sl.dart'; |
| 42 | +import 'messages_sq.dart'; |
| 43 | +import 'messages_sw.dart'; |
| 44 | +import 'messages_ta.dart'; |
| 45 | +import 'messages_th.dart'; |
| 46 | +import 'messages_tr.dart'; |
| 47 | +import 'messages_uk.dart'; |
| 48 | +import 'messages_vi.dart'; |
| 49 | +import 'messages_zh.dart'; |
| 50 | + |
| 51 | +/// Callers can lookup localized strings with an instance of FormBuilderLocalizationsImpl |
| 52 | +/// returned by `FormBuilderLocalizationsImpl.of(context)`. |
| 53 | +/// |
| 54 | +/// Applications need to include `FormBuilderLocalizationsImpl.delegate()` in their app's |
| 55 | +/// `localizationDelegates` list, and the locales they support in the app's |
| 56 | +/// `supportedLocales` list. For example: |
| 57 | +/// |
| 58 | +/// ```dart |
| 59 | +/// import 'intl/messages.dart'; |
| 60 | +/// |
| 61 | +/// return MaterialApp( |
| 62 | +/// localizationsDelegates: FormBuilderLocalizationsImpl.localizationsDelegates, |
| 63 | +/// supportedLocales: FormBuilderLocalizationsImpl.supportedLocales, |
| 64 | +/// home: MyApplicationHome(), |
| 65 | +/// ); |
| 66 | +/// ``` |
| 67 | +/// |
| 68 | +/// ## Update pubspec.yaml |
| 69 | +/// |
| 70 | +/// Please make sure to update your pubspec.yaml to include the following |
| 71 | +/// packages: |
| 72 | +/// |
| 73 | +/// ```yaml |
| 74 | +/// dependencies: |
| 75 | +/// # Internationalization support. |
| 76 | +/// flutter_localizations: |
| 77 | +/// sdk: flutter |
| 78 | +/// intl: any # Use the pinned version from flutter_localizations |
| 79 | +/// |
| 80 | +/// # Rest of dependencies |
| 81 | +/// ``` |
| 82 | +/// |
| 83 | +/// ## iOS Applications |
| 84 | +/// |
| 85 | +/// iOS applications define key application metadata, including supported |
| 86 | +/// locales, in an Info.plist file that is built into the application bundle. |
| 87 | +/// To configure the locales supported by your app, you’ll need to edit this |
| 88 | +/// file. |
| 89 | +/// |
| 90 | +/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file. |
| 91 | +/// Then, in the Project Navigator, open the Info.plist file under the Runner |
| 92 | +/// project’s Runner folder. |
| 93 | +/// |
| 94 | +/// Next, select the Information Property List item, select Add Item from the |
| 95 | +/// Editor menu, then select Localizations from the pop-up menu. |
| 96 | +/// |
| 97 | +/// Select and expand the newly-created Localizations item then, for each |
| 98 | +/// locale your application supports, add a new item and select the locale |
| 99 | +/// you wish to add from the pop-up menu in the Value field. This list should |
| 100 | +/// be consistent with the languages listed in the FormBuilderLocalizationsImpl.supportedLocales |
| 101 | +/// property. |
| 102 | +abstract class FormBuilderLocalizationsImpl { |
| 103 | + FormBuilderLocalizationsImpl(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString()); |
| 104 | + |
| 105 | + final String localeName; |
| 106 | + |
| 107 | + static FormBuilderLocalizationsImpl of(BuildContext context) { |
| 108 | + return Localizations.of<FormBuilderLocalizationsImpl>(context, FormBuilderLocalizationsImpl)!; |
| 109 | + } |
| 110 | + |
| 111 | + static const LocalizationsDelegate<FormBuilderLocalizationsImpl> delegate = _FormBuilderLocalizationsImplDelegate(); |
| 112 | + |
| 113 | + /// A list of this localizations delegate along with the default localizations |
| 114 | + /// delegates. |
| 115 | + /// |
| 116 | + /// Returns a list of localizations delegates containing this delegate along with |
| 117 | + /// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, |
| 118 | + /// and GlobalWidgetsLocalizations.delegate. |
| 119 | + /// |
| 120 | + /// Additional delegates can be added by appending to this list in |
| 121 | + /// MaterialApp. This list does not have to be used at all if a custom list |
| 122 | + /// of delegates is preferred or required. |
| 123 | + static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[ |
| 124 | + delegate, |
| 125 | + GlobalMaterialLocalizations.delegate, |
| 126 | + GlobalCupertinoLocalizations.delegate, |
| 127 | + GlobalWidgetsLocalizations.delegate, |
| 128 | + ]; |
| 129 | + |
| 130 | + /// A list of this localizations delegate's supported locales. |
| 131 | + static const List<Locale> supportedLocales = <Locale>[ |
| 132 | + Locale('sq'), |
| 133 | + Locale('ar'), |
| 134 | + Locale('bn'), |
| 135 | + Locale('bs'), |
| 136 | + Locale('ca'), |
| 137 | + Locale('cs'), |
| 138 | + Locale('da'), |
| 139 | + Locale('de'), |
| 140 | + Locale('el'), |
| 141 | + Locale('en'), |
| 142 | + Locale('es'), |
| 143 | + Locale('et'), |
| 144 | + Locale('fa'), |
| 145 | + Locale('fi'), |
| 146 | + Locale('fr'), |
| 147 | + Locale('he'), |
| 148 | + Locale('hr'), |
| 149 | + Locale('hu'), |
| 150 | + Locale('id'), |
| 151 | + Locale('it'), |
| 152 | + Locale('ja'), |
| 153 | + Locale('ko'), |
| 154 | + Locale('lo'), |
| 155 | + Locale('mn'), |
| 156 | + Locale('ms'), |
| 157 | + Locale('ne'), |
| 158 | + Locale('nl'), |
| 159 | + Locale('no'), |
| 160 | + Locale('pl'), |
| 161 | + Locale('pt'), |
| 162 | + Locale('ro'), |
| 163 | + Locale('ru'), |
| 164 | + Locale('se'), |
| 165 | + Locale('sk'), |
| 166 | + Locale('sl'), |
| 167 | + Locale('sw'), |
| 168 | + Locale('ta'), |
| 169 | + Locale('th'), |
| 170 | + Locale('tr'), |
| 171 | + Locale('uk'), |
| 172 | + Locale('vi'), |
| 173 | + Locale('zh'), |
| 174 | + Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant') |
| 175 | + ]; |
| 176 | + |
| 177 | + /// No description provided for @creditCardErrorText. |
| 178 | + /// |
| 179 | + /// In en, this message translates to: |
| 180 | + /// **'This field requires a valid credit card number.'** |
| 181 | + String get creditCardErrorText; |
| 182 | + |
| 183 | + /// No description provided for @dateStringErrorText. |
| 184 | + /// |
| 185 | + /// In en, this message translates to: |
| 186 | + /// **'This field requires a valid date string.'** |
| 187 | + String get dateStringErrorText; |
| 188 | + |
| 189 | + /// No description provided for @emailErrorText. |
| 190 | + /// |
| 191 | + /// In en, this message translates to: |
| 192 | + /// **'This field requires a valid email address.'** |
| 193 | + String get emailErrorText; |
| 194 | + |
| 195 | + /// No description provided for @equalErrorText. |
| 196 | + /// |
| 197 | + /// In en, this message translates to: |
| 198 | + /// **'This field value must be equal to {value}.'** |
| 199 | + String equalErrorText(Object value); |
| 200 | + |
| 201 | + /// No description provided for @equalLengthErrorText. |
| 202 | + /// |
| 203 | + /// In en, this message translates to: |
| 204 | + /// **'Value must have a length equal to {length}'** |
| 205 | + String equalLengthErrorText(Object length); |
| 206 | + |
| 207 | + /// No description provided for @integerErrorText. |
| 208 | + /// |
| 209 | + /// In en, this message translates to: |
| 210 | + /// **'This field requires a valid integer.'** |
| 211 | + String get integerErrorText; |
| 212 | + |
| 213 | + /// No description provided for @ipErrorText. |
| 214 | + /// |
| 215 | + /// In en, this message translates to: |
| 216 | + /// **'This field requires a valid IP.'** |
| 217 | + String get ipErrorText; |
| 218 | + |
| 219 | + /// No description provided for @matchErrorText. |
| 220 | + /// |
| 221 | + /// In en, this message translates to: |
| 222 | + /// **'Value does not match pattern.'** |
| 223 | + String get matchErrorText; |
| 224 | + |
| 225 | + /// No description provided for @maxErrorText. |
| 226 | + /// |
| 227 | + /// In en, this message translates to: |
| 228 | + /// **'Value must be less than or equal to {max}'** |
| 229 | + String maxErrorText(Object max); |
| 230 | + |
| 231 | + /// No description provided for @maxLengthErrorText. |
| 232 | + /// |
| 233 | + /// In en, this message translates to: |
| 234 | + /// **'Value must have a length less than or equal to {maxLength}'** |
| 235 | + String maxLengthErrorText(Object maxLength); |
| 236 | + |
| 237 | + /// No description provided for @maxWordsCountErrorText. |
| 238 | + /// |
| 239 | + /// In en, this message translates to: |
| 240 | + /// **'Value must have a words count less than or equal to {maxWordsCount}'** |
| 241 | + String maxWordsCountErrorText(Object maxWordsCount); |
| 242 | + |
| 243 | + /// No description provided for @minErrorText. |
| 244 | + /// |
| 245 | + /// In en, this message translates to: |
| 246 | + /// **'Value must be greater than or equal to {min}'** |
| 247 | + String minErrorText(Object min); |
| 248 | + |
| 249 | + /// No description provided for @minLengthErrorText. |
| 250 | + /// |
| 251 | + /// In en, this message translates to: |
| 252 | + /// **'Value must have a length greater than or equal to {minLength}'** |
| 253 | + String minLengthErrorText(Object minLength); |
| 254 | + |
| 255 | + /// No description provided for @minWordsCountErrorText. |
| 256 | + /// |
| 257 | + /// In en, this message translates to: |
| 258 | + /// **'Value must have a words count greater than or equal to {minWordsCount}'** |
| 259 | + String minWordsCountErrorText(Object minWordsCount); |
| 260 | + |
| 261 | + /// No description provided for @notEqualErrorText. |
| 262 | + /// |
| 263 | + /// In en, this message translates to: |
| 264 | + /// **'This field value must not be equal to {value}.'** |
| 265 | + String notEqualErrorText(Object value); |
| 266 | + |
| 267 | + /// No description provided for @numericErrorText. |
| 268 | + /// |
| 269 | + /// In en, this message translates to: |
| 270 | + /// **'Value must be numeric.'** |
| 271 | + String get numericErrorText; |
| 272 | + |
| 273 | + /// No description provided for @requiredErrorText. |
| 274 | + /// |
| 275 | + /// In en, this message translates to: |
| 276 | + /// **'This field cannot be empty.'** |
| 277 | + String get requiredErrorText; |
| 278 | + |
| 279 | + /// No description provided for @urlErrorText. |
| 280 | + /// |
| 281 | + /// In en, this message translates to: |
| 282 | + /// **'This field requires a valid URL address.'** |
| 283 | + String get urlErrorText; |
| 284 | +} |
| 285 | + |
| 286 | +class _FormBuilderLocalizationsImplDelegate extends LocalizationsDelegate<FormBuilderLocalizationsImpl> { |
| 287 | + const _FormBuilderLocalizationsImplDelegate(); |
| 288 | + |
| 289 | + @override |
| 290 | + Future<FormBuilderLocalizationsImpl> load(Locale locale) { |
| 291 | + return SynchronousFuture<FormBuilderLocalizationsImpl>(lookupFormBuilderLocalizationsImpl(locale)); |
| 292 | + } |
| 293 | + |
| 294 | + @override |
| 295 | + bool isSupported(Locale locale) => <String>['sq', 'ar', 'bn', 'bs', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es', 'et', 'fa', 'fi', 'fr', 'he', 'hr', 'hu', 'id', 'it', 'ja', 'ko', 'lo', 'mn', 'ms', 'ne', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'se', 'sk', 'sl', 'sw', 'ta', 'th', 'tr', 'uk', 'vi', 'zh'].contains(locale.languageCode); |
| 296 | + |
| 297 | + @override |
| 298 | + bool shouldReload(_FormBuilderLocalizationsImplDelegate old) => false; |
| 299 | +} |
| 300 | + |
| 301 | +FormBuilderLocalizationsImpl lookupFormBuilderLocalizationsImpl(Locale locale) { |
| 302 | + |
| 303 | + // Lookup logic when language+script codes are specified. |
| 304 | + switch (locale.languageCode) { |
| 305 | + case 'zh': { |
| 306 | + switch (locale.scriptCode) { |
| 307 | + case 'Hant': return FormBuilderLocalizationsImplZhHant(); |
| 308 | + } |
| 309 | + break; |
| 310 | + } |
| 311 | + } |
| 312 | + |
| 313 | + // Lookup logic when only language code is specified. |
| 314 | + switch (locale.languageCode) { |
| 315 | + case 'sq': return FormBuilderLocalizationsImplSq(); |
| 316 | + case 'ar': return FormBuilderLocalizationsImplAr(); |
| 317 | + case 'bn': return FormBuilderLocalizationsImplBn(); |
| 318 | + case 'bs': return FormBuilderLocalizationsImplBs(); |
| 319 | + case 'ca': return FormBuilderLocalizationsImplCa(); |
| 320 | + case 'cs': return FormBuilderLocalizationsImplCs(); |
| 321 | + case 'da': return FormBuilderLocalizationsImplDa(); |
| 322 | + case 'de': return FormBuilderLocalizationsImplDe(); |
| 323 | + case 'el': return FormBuilderLocalizationsImplEl(); |
| 324 | + case 'en': return FormBuilderLocalizationsImplEn(); |
| 325 | + case 'es': return FormBuilderLocalizationsImplEs(); |
| 326 | + case 'et': return FormBuilderLocalizationsImplEt(); |
| 327 | + case 'fa': return FormBuilderLocalizationsImplFa(); |
| 328 | + case 'fi': return FormBuilderLocalizationsImplFi(); |
| 329 | + case 'fr': return FormBuilderLocalizationsImplFr(); |
| 330 | + case 'he': return FormBuilderLocalizationsImplHe(); |
| 331 | + case 'hr': return FormBuilderLocalizationsImplHr(); |
| 332 | + case 'hu': return FormBuilderLocalizationsImplHu(); |
| 333 | + case 'id': return FormBuilderLocalizationsImplId(); |
| 334 | + case 'it': return FormBuilderLocalizationsImplIt(); |
| 335 | + case 'ja': return FormBuilderLocalizationsImplJa(); |
| 336 | + case 'ko': return FormBuilderLocalizationsImplKo(); |
| 337 | + case 'lo': return FormBuilderLocalizationsImplLo(); |
| 338 | + case 'mn': return FormBuilderLocalizationsImplMn(); |
| 339 | + case 'ms': return FormBuilderLocalizationsImplMs(); |
| 340 | + case 'ne': return FormBuilderLocalizationsImplNe(); |
| 341 | + case 'nl': return FormBuilderLocalizationsImplNl(); |
| 342 | + case 'no': return FormBuilderLocalizationsImplNo(); |
| 343 | + case 'pl': return FormBuilderLocalizationsImplPl(); |
| 344 | + case 'pt': return FormBuilderLocalizationsImplPt(); |
| 345 | + case 'ro': return FormBuilderLocalizationsImplRo(); |
| 346 | + case 'ru': return FormBuilderLocalizationsImplRu(); |
| 347 | + case 'se': return FormBuilderLocalizationsImplSe(); |
| 348 | + case 'sk': return FormBuilderLocalizationsImplSk(); |
| 349 | + case 'sl': return FormBuilderLocalizationsImplSl(); |
| 350 | + case 'sw': return FormBuilderLocalizationsImplSw(); |
| 351 | + case 'ta': return FormBuilderLocalizationsImplTa(); |
| 352 | + case 'th': return FormBuilderLocalizationsImplTh(); |
| 353 | + case 'tr': return FormBuilderLocalizationsImplTr(); |
| 354 | + case 'uk': return FormBuilderLocalizationsImplUk(); |
| 355 | + case 'vi': return FormBuilderLocalizationsImplVi(); |
| 356 | + case 'zh': return FormBuilderLocalizationsImplZh(); |
| 357 | + } |
| 358 | + |
| 359 | + throw FlutterError( |
| 360 | + 'FormBuilderLocalizationsImpl.delegate failed to load unsupported locale "$locale". This is likely ' |
| 361 | + 'an issue with the localizations generation tool. Please file an issue ' |
| 362 | + 'on GitHub with a reproducible sample app and the gen-l10n configuration ' |
| 363 | + 'that was used.' |
| 364 | + ); |
| 365 | +} |
0 commit comments