material_localizations.dart 29.8 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'dart:async';
6

7 8
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
9

10
import 'reorderable_list.dart';
11
import 'text_theme.dart';
12
import 'time.dart';
13
import 'typography.dart';
14

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
// ADDING A NEW STRING
//
// If you (someone contributing to the Flutter framework) want to add a new
// string to the MaterialLocalizations object (e.g. because you've added a new
// widget and it has a tooltip), follow these steps:
//
// 1. Add the new getter to MaterialLocalizations below.
//
// 2. Implement a default value in DefaultMaterialLocalizations below.
//
// 3. Add a test to test/material/localizations_test.dart that verifies that
//    this new value is implemented.
//
// 4. Update the flutter_localizations package. To add a new string to the
//    flutter_localizations package, you must first add it to the English
30 31
//    translations (lib/src/l10n/material_en.arb), including a description.
//
32
//    Then you need to add new entries for the string to all of the other
33 34 35 36
//    language locale files by running:
//    ```
//    dart dev/tools/localization/bin/gen_missing_localizations.dart
//    ```
37 38
//    Which will copy the english strings into the other locales as placeholders
//    until they can be translated.
39 40 41 42 43 44
//
//    Finally you need to re-generate lib/src/l10n/localizations.dart by running:
//    ```
//    dart dev/tools/localization/bin/gen_localizations.dart --overwrite
//    ```
//
45 46
//    There is a README file with further information in the lib/src/l10n/
//    directory.
47 48 49 50
//
// 5. If you are a Google employee, you should then also follow the instructions
//    at go/flutter-l10n. If you're not, don't worry about it.

Yegor's avatar
Yegor committed
51
/// Defines the localized resource values used by the Material widgets.
52 53 54
///
/// See also:
///
55 56 57 58
///  * [DefaultMaterialLocalizations], the default, English-only, implementation
///    of this interface.
///  * [GlobalMaterialLocalizations], which provides material localizations for
///    many languages.
59
abstract class MaterialLocalizations {
60
  /// The tooltip for the leading [AppBar] menu (a.k.a. 'hamburger') button.
61
  String get openAppDrawerTooltip;
62 63

  /// The [BackButton]'s tooltip.
64
  String get backButtonTooltip;
65 66

  /// The [CloseButton]'s tooltip.
67
  String get closeButtonTooltip;
68

69 70 71
  /// The tooltip for the delete button on a [Chip].
  String get deleteButtonTooltip;

72 73 74
  /// The tooltip for the more button on an overflowing text selection menu.
  String get moreButtonTooltip;

75
  /// The tooltip for the [MonthPicker]'s "next month" button.
76
  String get nextMonthTooltip;
77 78

  /// The tooltip for the [MonthPicker]'s "previous month" button.
79
  String get previousMonthTooltip;
80

81
  /// The tooltip for the [PaginatedDataTable]'s "next page" button.
82 83
  String get nextPageTooltip;

84
  /// The tooltip for the [PaginatedDataTable]'s "previous page" button.
85 86 87 88 89
  String get previousPageTooltip;

  /// The default [PopupMenuButton] tooltip.
  String get showMenuTooltip;

Hans Muller's avatar
Hans Muller committed
90 91 92
  /// The default title for [AboutListTile].
  String aboutListTileTitle(String applicationName);

93 94 95
  /// Title for the [LicensePage] widget.
  String get licensesPageTitle;

96 97 98 99 100 101
  /// Title for the [PaginatedDataTable]'s row info footer.
  String pageRowsInfoTitle(int firstRow, int lastRow, int rowCount, bool rowCountIsApproximate);

  /// Title for the [PaginatedDataTable]'s "rows per page" footer.
  String get rowsPerPageTitle;

102 103 104 105 106 107
  /// The accessibility label used on a tab in a [TabBar].
  ///
  /// This message describes the index of the selected tab and how many tabs
  /// there are, e.g. 'Tab 1 of 2' in United States English.
  ///
  /// `tabIndex` and `tabCount` must be greater than or equal to one.
108
  String tabLabel({ int tabIndex, int tabCount });
109

110
  /// Title for the [PaginatedDataTable]'s selected row count header.
111 112
  String selectedRowCountTitle(int selectedRowCount);

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
  /// Label for "cancel" buttons and menu items.
  String get cancelButtonLabel;

  /// Label for "close" buttons and menu items.
  String get closeButtonLabel;

  /// Label for "continue" buttons and menu items.
  String get continueButtonLabel;

  /// Label for "copy" edit buttons and menu items.
  String get copyButtonLabel;

  /// Label for "cut" edit buttons and menu items.
  String get cutButtonLabel;

  /// Label for OK buttons and menu items.
  String get okButtonLabel;

  /// Label for "paste" edit buttons and menu items.
  String get pasteButtonLabel;

  /// Label for "select all" edit buttons and menu items.
  String get selectAllButtonLabel;

137
  /// Label for the [AboutDialog] button that shows the [LicensePage].
138 139
  String get viewLicensesButtonLabel;

Yegor's avatar
Yegor committed
140 141 142 143 144 145
  /// The abbreviation for ante meridiem (before noon) shown in the time picker.
  String get anteMeridiemAbbreviation;

  /// The abbreviation for post meridiem (after noon) shown in the time picker.
  String get postMeridiemAbbreviation;

146 147 148 149 150 151 152 153
  /// The text-to-speech announcement made when a time picker invoked using
  /// [showTimePicker] is set to the hour picker mode.
  String get timePickerHourModeAnnouncement;

  /// The text-to-speech announcement made when a time picker invoked using
  /// [showTimePicker] is set to the minute picker mode.
  String get timePickerMinuteModeAnnouncement;

Josh Soref's avatar
Josh Soref committed
154
  /// Label read out by accessibility tools (TalkBack or VoiceOver) for a modal
155 156
  /// barrier to indicate that a tap dismisses the barrier.
  ///
157
  /// A modal barrier can for example be found behind an alert or popup to block
158 159 160
  /// user interaction with elements behind it.
  String get modalBarrierDismissLabel;

161
  /// Label read out by accessibility tools (TalkBack or VoiceOver) when a
162 163
  /// drawer widget is opened.
  String get drawerLabel;
164 165

  /// Label read out by accessibility tools (TalkBack or VoiceOver) when a
166 167 168
  /// popup menu widget is opened.
  String get popupMenuLabel;

169
  /// Label read out by accessibility tools (TalkBack or VoiceOver) when a
170 171 172
  /// dialog widget is opened.
  String get dialogLabel;

173
  /// Label read out by accessibility tools (TalkBack or VoiceOver) when an
174 175 176
  /// alert dialog widget is opened.
  String get alertDialogLabel;

177 178 179 180
  /// Label indicating that a text field is a search field. This will be used
  /// as a hint text in the text field.
  String get searchFieldLabel;

Yegor's avatar
Yegor committed
181 182 183 184
  /// The format used to lay out the time picker.
  ///
  /// The documentation for [TimeOfDayFormat] enum values provides details on
  /// each supported layout.
185
  TimeOfDayFormat timeOfDayFormat({ bool alwaysUse24HourFormat = false });
Yegor's avatar
Yegor committed
186

187
  /// Defines the localized [TextStyle] geometry for [ThemeData.textTheme].
188
  ///
189
  /// The [scriptCategory] defines the overall geometry of a [TextTheme] for
Dan Field's avatar
Dan Field committed
190
  /// the [Typography.geometryThemeFor] method in terms of the
191
  /// three language categories defined in https://material.io/go/design-typography.
192
  ///
193 194 195 196 197
  /// Generally speaking, font sizes for [ScriptCategory.tall] and
  /// [ScriptCategory.dense] scripts - for text styles that are smaller than the
  /// title style - are one unit larger than they are for
  /// [ScriptCategory.englishLike] scripts.
  ScriptCategory get scriptCategory;
198

199 200 201 202
  /// Formats [number] as a decimal, inserting locale-appropriate thousands
  /// separators as necessary.
  String formatDecimal(int number);

203 204
  /// Formats [TimeOfDay.hour] in the given time of day according to the value
  /// of [timeOfDayFormat].
205 206 207
  ///
  /// If [alwaysUse24HourFormat] is true, formats hour using [HourFormat.HH]
  /// rather than the default for the current locale.
208
  String formatHour(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false });
209 210 211 212 213 214

  /// Formats [TimeOfDay.minute] in the given time of day according to the value
  /// of [timeOfDayFormat].
  String formatMinute(TimeOfDay timeOfDay);

  /// Formats [timeOfDay] according to the value of [timeOfDayFormat].
215 216 217 218 219
  ///
  /// If [alwaysUse24HourFormat] is true, formats hour using [HourFormat.HH]
  /// rather than the default for the current locale. This value is usually
  /// passed from [MediaQueryData.alwaysUse24HourFormat], which has platform-
  /// specific behavior.
220
  String formatTimeOfDay(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false });
221

Yegor's avatar
Yegor committed
222 223 224
  /// Full unabbreviated year format, e.g. 2017 rather than 17.
  String formatYear(DateTime date);

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
  /// Formats the date in a compact format.
  ///
  /// Usually just the numeric values for the for day, month and year are used.
  ///
  /// Examples:
  ///
  /// - US English: 02/21/2019
  /// - Russian: 21.02.2019
  ///
  /// See also:
  ///   * [parseCompactDate], which will convert a compact date string to a [DateTime].
  String formatCompactDate(DateTime date);

  /// Formats the date using a short-width format.
  ///
  /// Includes the abbreviation of the month, the day and year.
  ///
  /// Examples:
  ///
  /// - US English: Feb 21, 2019
  /// - Russian: 21 февр. 2019 г.
  String formatShortDate(DateTime date);

Yegor's avatar
Yegor committed
248 249 250 251 252 253 254 255 256 257 258
  /// Formats the date using a medium-width format.
  ///
  /// Abbreviates month and days of week. This appears in the header of the date
  /// picker invoked using [showDatePicker].
  ///
  /// Examples:
  ///
  /// - US English: Wed, Sep 27
  /// - Russian: ср, сент. 27
  String formatMediumDate(DateTime date);

259 260 261 262 263 264 265 266 267 268 269
  /// Formats day of week, month, day of month and year in a long-width format.
  ///
  /// Does not abbreviate names. Appears in spoken announcements of the date
  /// picker invoked using [showDatePicker], when accessibility mode is on.
  ///
  /// Examples:
  ///
  /// - US English: Wednesday, September 27, 2017
  /// - Russian: Среда, Сентябрь 27, 2017
  String formatFullDate(DateTime date);

Yegor's avatar
Yegor committed
270 271 272 273 274 275
  /// Formats the month and the year of the given [date].
  ///
  /// The returned string does not contain the day of the month. This appears
  /// in the date picker invoked using [showDatePicker].
  String formatMonthYear(DateTime date);

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
  /// Formats the month and day of the given [date].
  ///
  /// Examples:
  ///
  /// - US English: Feb 21
  /// - Russian: 21 февр.
  String formatShortMonthDay(DateTime date);

  /// Converts the given compact date formatted string into a [DateTime].
  ///
  /// The format of the string must be a valid compact date format for the
  /// given locale. If the text doesn't represent a valid date, `null` will be
  /// returned.
  ///
  /// See also:
  ///   * [formatCompactDate], which will convert a [DateTime] into a string in the compact format.
  DateTime parseCompactDate(String inputString);

Yegor's avatar
Yegor committed
294 295 296 297 298 299 300 301 302 303 304 305
  /// List of week day names in narrow format, usually 1- or 2-letter
  /// abbreviations of full names.
  ///
  /// The list begins with the value corresponding to Sunday and ends with
  /// Saturday. Use [firstDayOfWeekIndex] to find the first day of week in this
  /// list.
  ///
  /// Examples:
  ///
  /// - US English: S, M, T, W, T, F, S
  /// - Russian: вс, пн, вт, ср, чт, пт, сб - notice that the list begins with
  ///   вс (Sunday) even though the first day of week for Russian is Monday.
306
  List<String> get narrowWeekdays;
Yegor's avatar
Yegor committed
307 308 309 310

  /// Index of the first day of week, where 0 points to Sunday, and 6 points to
  /// Saturday.
  ///
311
  /// This getter is compatible with [narrowWeekdays]. For example:
Yegor's avatar
Yegor committed
312 313 314 315
  ///
  /// ```dart
  /// var localizations = MaterialLocalizations.of(context);
  /// // The name of the first day of week for the current locale.
316
  /// var firstDayOfWeek = localizations.narrowWeekdays[localizations.firstDayOfWeekIndex];
Yegor's avatar
Yegor committed
317 318 319
  /// ```
  int get firstDayOfWeekIndex;

320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
  /// The character string used to separate the parts of a compact date format
  /// (i.e. mm/dd/yyyy has a separator of '/').
  String get dateSeparator;

  /// The help text used on an empty [InputDatePickerFormField] to indicate
  /// to the user the date format being asked for.
  String get dateHelpText;

  /// The semantic label used to announce when the user has entered the year
  /// selection mode of the [CalendarDatePicker] which is used in the data picker
  /// dialog created with [showDatePicker].
  String get selectYearSemanticsLabel;

  /// The label used to indicate a date that has not been entered or selected
  /// yet in the date picker.
  String get unspecifiedDate;

  /// The label used to indicate a date range that has not been entered or
  /// selected yet in the date range picker.
  String get unspecifiedDateRange;

  /// The label used to describe the text field used in an [InputDatePickerFormField].
  String get dateInputLabel;

  /// The label used for the starting date input field in the date range picker
  /// created with [showDateRangePicker].
  String get dateRangeStartLabel;

  /// The label used for the ending date input field in the date range picker
  /// created with [showDateRangePicker].
  String get dateRangeEndLabel;

  /// The semantics label used for the selected start date in the date range
  /// picker's day grid.
  String dateRangeStartDateSemanticLabel(String formattedDate);

  /// The semantics label used for the selected end date in the date range
  /// picker's day grid.
  String dateRangeEndDateSemanticLabel(String formattedDate);

  /// Error message displayed to the user when they have entered a text string
  /// in an [InputDatePickerFormField] that is not in a valid date format.
  String get invalidDateFormatLabel;

  /// Error message displayed to the user when they have entered an invalid
  /// date range in the input mode of the date range picker created with
  /// [showDateRangePicker].
  String get invalidDateRangeLabel;

  /// Error message displayed to the user when they have entered a date that
  /// is outside the valid range for the date picker.
  /// [showDateRangePicker].
  String get dateOutOfRangeLabel;

  /// Label for a 'SAVE' button. Currently used by the full screen mode of the
  /// date range picker.
  String get saveButtonLabel;

  /// Label used in the header of the date picker dialog created with
  /// [showDatePicker].
  String get datePickerHelpText;

  /// Label used in the header of the date range picker dialog created with
  /// [showDateRangePicker].
  String get dateRangePickerHelpText;

  /// Tooltip used for the calendar mode button of the date pickers.
  String get calendarModeButtonLabel;

  /// Tooltip used for the text input mode button of the date pickers.
  String get inputDateModeButtonLabel;

392 393 394 395 396 397 398 399 400 401 402 403
  /// The semantics label used to indicate which account is signed in in the
  /// [UserAccountsDrawerHeader] widget.
  String get signedInLabel;

  /// The semantics label used for the button on [UserAccountsDrawerHeader] that
  /// hides the list of accounts.
  String get hideAccountsLabel;

  /// The semantics label used for the button on [UserAccountsDrawerHeader] that
  /// shows the list of accounts.
  String get showAccountsLabel;

404
  /// The semantics label used for [ReorderableListView] to reorder an item in the
405 406 407
  /// list to the start of the list.
  String get reorderItemToStart;

408
  /// The semantics label used for [ReorderableListView] to reorder an item in the
409 410 411
  /// list to the end of the list.
  String get reorderItemToEnd;

412
  /// The semantics label used for [ReorderableListView] to reorder an item in the
413 414 415
  /// list one space up the list.
  String get reorderItemUp;

416
  /// The semantics label used for [ReorderableListView] to reorder an item in the
417 418 419
  /// list one space down the list.
  String get reorderItemDown;

420
  /// The semantics label used for [ReorderableListView] to reorder an item in the
421 422 423
  /// list one space left in the list.
  String get reorderItemLeft;

424
  /// The semantics label used for [ReorderableListView] to reorder an item in the
425 426 427
  /// list one space right in the list.
  String get reorderItemRight;

428 429 430 431 432 433
  /// The semantics hint to describe the tap action on an expanded [ExpandIcon].
  String get expandedIconTapHint => 'Collapse';

  /// The semantics hint to describe the tap action on a collapsed [ExpandIcon].
  String get collapsedIconTapHint => 'Expand';

434 435 436
  /// The label for the [TextField]'s character counter.
  String remainingTextFieldCharacterCount(int remaining);

437 438 439
  /// The default semantics label for a [RefreshIndicator].
  String get refreshIndicatorSemanticLabel;

440 441 442 443 444 445 446 447
  /// The `MaterialLocalizations` from the closest [Localizations] instance
  /// that encloses the given context.
  ///
  /// This method is just a convenient shorthand for:
  /// `Localizations.of<MaterialLocalizations>(context, MaterialLocalizations)`.
  ///
  /// References to the localized resources defined by this class are typically
  /// written in terms of this method. For example:
448
  ///
449 450 451 452 453 454 455
  /// ```dart
  /// tooltip: MaterialLocalizations.of(context).backButtonTooltip,
  /// ```
  static MaterialLocalizations of(BuildContext context) {
    return Localizations.of<MaterialLocalizations>(context, MaterialLocalizations);
  }
}
456

457 458 459
class _MaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLocalizations> {
  const _MaterialLocalizationsDelegate();

460 461 462
  @override
  bool isSupported(Locale locale) => locale.languageCode == 'en';

463 464 465 466 467
  @override
  Future<MaterialLocalizations> load(Locale locale) => DefaultMaterialLocalizations.load(locale);

  @override
  bool shouldReload(_MaterialLocalizationsDelegate old) => false;
468 469 470

  @override
  String toString() => 'DefaultMaterialLocalizations.delegate(en_US)';
471 472 473 474 475 476 477 478
}

/// US English strings for the material widgets.
///
/// See also:
///
///  * [GlobalMaterialLocalizations], which provides material localizations for
///    many languages.
Dan Field's avatar
Dan Field committed
479
///  * [MaterialApp.localizationsDelegates], which automatically includes
480
///    [DefaultMaterialLocalizations.delegate] by default.
481
class DefaultMaterialLocalizations implements MaterialLocalizations {
Yegor's avatar
Yegor committed
482
  /// Constructs an object that defines the material widgets' localized strings
483
  /// for US English (only).
484 485 486
  ///
  /// [LocalizationsDelegate] implementations typically call the static [load]
  /// function, rather than constructing this class directly.
487 488
  const DefaultMaterialLocalizations();

489
  // Ordered to match DateTime.monday=1, DateTime.sunday=6
490
  static const List<String> _shortWeekdays = <String>[
491 492 493 494 495 496 497 498 499
    'Mon',
    'Tue',
    'Wed',
    'Thu',
    'Fri',
    'Sat',
    'Sun',
  ];

500
  // Ordered to match DateTime.monday=1, DateTime.sunday=6
501
  static const List<String> _weekdays = <String>[
502 503 504 505 506 507 508 509 510
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday',
    'Sunday',
  ];

511
  static const List<String> _narrowWeekdays = <String>[
512 513 514 515 516 517 518 519 520
    'S',
    'M',
    'T',
    'W',
    'T',
    'F',
    'S',
  ];

521
  static const List<String> _shortMonths = <String>[
522 523 524 525 526 527 528 529 530 531 532 533 534 535
    'Jan',
    'Feb',
    'Mar',
    'Apr',
    'May',
    'Jun',
    'Jul',
    'Aug',
    'Sep',
    'Oct',
    'Nov',
    'Dec',
  ];

536
  static const List<String> _months = <String>[
537 538 539 540 541 542 543 544 545 546 547 548 549
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July',
    'August',
    'September',
    'October',
    'November',
    'December',
  ];
550

551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
  /// Returns the number of days in a month, according to the proleptic
  /// Gregorian calendar.
  ///
  /// This applies the leap year logic introduced by the Gregorian reforms of
  /// 1582. It will not give valid results for dates prior to that time.
  int _getDaysInMonth(int year, int month) {
    if (month == DateTime.february) {
      final bool isLeapYear = (year % 4 == 0) && (year % 100 != 0) ||
          (year % 400 == 0);
      if (isLeapYear)
        return 29;
      return 28;
    }
    const List<int> daysInMonth = <int>[31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    return daysInMonth[month - 1];
  }

568
  @override
569
  String formatHour(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false }) {
570 571 572 573 574 575 576
    final TimeOfDayFormat format = timeOfDayFormat(alwaysUse24HourFormat: alwaysUse24HourFormat);
    switch (format) {
      case TimeOfDayFormat.h_colon_mm_space_a:
        return formatDecimal(timeOfDay.hourOfPeriod == 0 ? 12 : timeOfDay.hourOfPeriod);
      case TimeOfDayFormat.HH_colon_mm:
        return _formatTwoDigitZeroPad(timeOfDay.hour);
      default:
577
        throw AssertionError('$runtimeType does not support $format.');
578 579 580 581 582 583 584 585 586 587 588 589
    }
  }

  /// Formats [number] using two digits, assuming it's in the 0-99 inclusive
  /// range. Not designed to format values outside this range.
  String _formatTwoDigitZeroPad(int number) {
    assert(0 <= number && number < 100);

    if (number < 10)
      return '0$number';

    return '$number';
590 591 592 593
  }

  @override
  String formatMinute(TimeOfDay timeOfDay) {
594 595
    final int minute = timeOfDay.minute;
    return minute < 10 ? '0$minute' : minute.toString();
596 597
  }

Yegor's avatar
Yegor committed
598
  @override
599
  String formatYear(DateTime date) => date.year.toString();
Yegor's avatar
Yegor committed
600

601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
  @override
  String formatCompactDate(DateTime date) {
    // Assumes US mm/dd/yyyy format
    final String month = _formatTwoDigitZeroPad(date.month);
    final String day = _formatTwoDigitZeroPad(date.day);
    final String year = date.year.toString().padLeft(4, '0');
    return '$month/$day/$year';
  }

  @override
  String formatShortDate(DateTime date) {
    final String month = _shortMonths[date.month - DateTime.january];
    return '$month ${date.day}, ${date.year}';
  }

Yegor's avatar
Yegor committed
616 617
  @override
  String formatMediumDate(DateTime date) {
618 619
    final String day = _shortWeekdays[date.weekday - DateTime.monday];
    final String month = _shortMonths[date.month - DateTime.january];
620
    return '$day, $month ${date.day}';
Yegor's avatar
Yegor committed
621 622
  }

623 624
  @override
  String formatFullDate(DateTime date) {
625 626
    final String month = _months[date.month - DateTime.january];
    return '${_weekdays[date.weekday - DateTime.monday]}, $month ${date.day}, ${date.year}';
627 628
  }

Yegor's avatar
Yegor committed
629 630
  @override
  String formatMonthYear(DateTime date) {
631
    final String year = formatYear(date);
632
    final String month = _months[date.month - DateTime.january];
633
    return '$month $year';
Yegor's avatar
Yegor committed
634 635
  }

636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
  @override
  String formatShortMonthDay(DateTime date) {
    final String month = _shortMonths[date.month - DateTime.january];
    return '$month ${date.day}';
  }

  @override
  DateTime parseCompactDate(String inputString) {
    // Assumes US mm/dd/yyyy format
    final List<String> inputParts = inputString.split('/');
    if (inputParts.length != 3) {
      return null;
    }

    final int year = int.tryParse(inputParts[2], radix: 10);
    if (year == null || year < 1) {
      return null;
    }

    final int month = int.tryParse(inputParts[0], radix: 10);
    if (month == null || month < 1 || month > 12) {
      return null;
    }

    final int day = int.tryParse(inputParts[1], radix: 10);
    if (day == null || day < 1 || day > _getDaysInMonth(year, month)) {
      return null;
    }
    return DateTime(year, month, day);
  }

Yegor's avatar
Yegor committed
667
  @override
668
  List<String> get narrowWeekdays => _narrowWeekdays;
Yegor's avatar
Yegor committed
669 670

  @override
671
  int get firstDayOfWeekIndex => 0; // narrowWeekdays[0] is 'S' for Sunday
Yegor's avatar
Yegor committed
672

673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
  @override
  String get dateSeparator => '/';

  @override
  String get dateHelpText => 'mm/dd/yyyy';

  @override
  String get selectYearSemanticsLabel => 'Select year';

  @override
  String get unspecifiedDate => 'Date';

  @override
  String get unspecifiedDateRange => 'Date Range';

  @override
  String get dateInputLabel => 'Enter Date';

  @override
  String get dateRangeStartLabel => 'Start Date';

  @override
  String get dateRangeEndLabel => 'End Date';

  @override
  String dateRangeStartDateSemanticLabel(String fullDate) => 'Start date $fullDate';

  @override
  String dateRangeEndDateSemanticLabel(String fullDate) => 'End date $fullDate';

  @override
  String get invalidDateFormatLabel => 'Invalid format.';

  @override
  String get invalidDateRangeLabel => 'Invalid range.';

  @override
  String get dateOutOfRangeLabel => 'Out of range.';

  @override
  String get saveButtonLabel => 'SAVE';

  @override
  String get datePickerHelpText => 'SELECT DATE';

  @override
  String get dateRangePickerHelpText => 'SELECT RANGE';

  @override
  String get calendarModeButtonLabel => 'Switch to calendar';

  @override
  String get inputDateModeButtonLabel => 'Switch to input';

727 728 729 730 731 732 733 734 735 736
  String _formatDayPeriod(TimeOfDay timeOfDay) {
    switch (timeOfDay.period) {
      case DayPeriod.am:
        return anteMeridiemAbbreviation;
      case DayPeriod.pm:
        return postMeridiemAbbreviation;
    }
    return null;
  }

737
  @override
738
  String formatDecimal(int number) {
739 740 741 742
    if (number > -1000 && number < 1000)
      return number.toString();

    final String digits = number.abs().toString();
743
    final StringBuffer result = StringBuffer(number < 0 ? '-' : '');
744 745 746 747 748 749 750
    final int maxDigitIndex = digits.length - 1;
    for (int i = 0; i <= maxDigitIndex; i += 1) {
      result.write(digits[i]);
      if (i < maxDigitIndex && (maxDigitIndex - i) % 3 == 0)
        result.write(',');
    }
    return result.toString();
751 752 753
  }

  @override
754
  String formatTimeOfDay(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false }) {
755 756 757 758 759 760 761 762
    // Not using intl.DateFormat for two reasons:
    //
    // - DateFormat supports more formats than our material time picker does,
    //   and we want to be consistent across time picker format and the string
    //   formatting of the time of day.
    // - DateFormat operates on DateTime, which is sensitive to time eras and
    //   time zones, while here we want to format hour and minute within one day
    //   no matter what date the day falls on.
763
    final StringBuffer buffer = StringBuffer();
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780

    // Add hour:minute.
    buffer
      ..write(formatHour(timeOfDay, alwaysUse24HourFormat: alwaysUse24HourFormat))
      ..write(':')
      ..write(formatMinute(timeOfDay));

    if (alwaysUse24HourFormat) {
      // There's no AM/PM indicator in 24-hour format.
      return '$buffer';
    }

    // Add AM/PM indicator.
    buffer
      ..write(' ')
      ..write(_formatDayPeriod(timeOfDay));
    return '$buffer';
781 782
  }

783
  @override
784
  String get openAppDrawerTooltip => 'Open navigation menu';
785 786

  @override
787
  String get backButtonTooltip => 'Back';
788 789

  @override
790
  String get closeButtonTooltip => 'Close';
791

792 793 794
  @override
  String get deleteButtonTooltip => 'Delete';

795 796 797
  @override
  String get moreButtonTooltip => 'More';

798
  @override
799
  String get nextMonthTooltip => 'Next month';
800 801

  @override
802
  String get previousMonthTooltip => 'Previous month';
803

804
  @override
805
  String get nextPageTooltip => 'Next page';
806 807

  @override
808
  String get previousPageTooltip => 'Previous page';
809 810

  @override
811
  String get showMenuTooltip => 'Show menu';
812

813 814 815 816 817 818 819 820 821 822 823 824
  @override
  String get drawerLabel => 'Navigation menu';

  @override
  String get popupMenuLabel => 'Popup menu';

  @override
  String get dialogLabel => 'Dialog';

  @override
  String get alertDialogLabel => 'Alert';

825 826 827
  @override
  String get searchFieldLabel => 'Search';

Hans Muller's avatar
Hans Muller committed
828
  @override
829
  String aboutListTileTitle(String applicationName) => 'About $applicationName';
Hans Muller's avatar
Hans Muller committed
830

831
  @override
832
  String get licensesPageTitle => 'Licenses';
833 834 835

  @override
  String pageRowsInfoTitle(int firstRow, int lastRow, int rowCount, bool rowCountIsApproximate) {
836 837 838
    return rowCountIsApproximate
      ? '$firstRow$lastRow of about $rowCount'
      : '$firstRow$lastRow of $rowCount';
839 840 841
  }

  @override
842
  String get rowsPerPageTitle => 'Rows per page:';
843

844
  @override
845
  String tabLabel({ int tabIndex, int tabCount }) {
846 847 848 849 850
    assert(tabIndex >= 1);
    assert(tabCount >= 1);
    return 'Tab $tabIndex of $tabCount';
  }

851 852
  @override
  String selectedRowCountTitle(int selectedRowCount) {
853 854 855 856 857 858 859 860
    switch (selectedRowCount) {
      case 0:
        return 'No items selected';
      case 1:
        return '1 item selected';
      default:
        return '$selectedRowCount items selected';
    }
861
  }
862 863

  @override
864
  String get cancelButtonLabel => 'CANCEL';
865 866

  @override
867
  String get closeButtonLabel => 'CLOSE';
868 869

  @override
870
  String get continueButtonLabel => 'CONTINUE';
871 872

  @override
873
  String get copyButtonLabel => 'COPY';
874 875

  @override
876
  String get cutButtonLabel => 'CUT';
877 878

  @override
879
  String get okButtonLabel => 'OK';
880 881

  @override
882
  String get pasteButtonLabel => 'PASTE';
883 884

  @override
885
  String get selectAllButtonLabel => 'SELECT ALL';
886 887

  @override
888
  String get viewLicensesButtonLabel => 'VIEW LICENSES';
889

Yegor's avatar
Yegor committed
890
  @override
891
  String get anteMeridiemAbbreviation => 'AM';
Yegor's avatar
Yegor committed
892 893

  @override
894
  String get postMeridiemAbbreviation => 'PM';
Yegor's avatar
Yegor committed
895

896 897 898 899 900 901
  @override
  String get timePickerHourModeAnnouncement => 'Select hours';

  @override
  String get timePickerMinuteModeAnnouncement => 'Select minutes';

902 903 904
  @override
  String get modalBarrierDismissLabel => 'Dismiss';

905 906 907
  @override
  ScriptCategory get scriptCategory => ScriptCategory.englishLike;

908
  @override
909
  TimeOfDayFormat timeOfDayFormat({ bool alwaysUse24HourFormat = false }) {
910 911 912 913
    return alwaysUse24HourFormat
      ? TimeOfDayFormat.HH_colon_mm
      : TimeOfDayFormat.h_colon_mm_space_a;
  }
Yegor's avatar
Yegor committed
914

915 916 917 918 919 920 921 922 923
  @override
  String get signedInLabel => 'Signed in';

  @override
  String get hideAccountsLabel => 'Hide accounts';

  @override
  String get showAccountsLabel => 'Show accounts';

924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
  @override
  String get reorderItemUp => 'Move up';

  @override
  String get reorderItemDown => 'Move down';

  @override
  String get reorderItemLeft => 'Move left';

  @override
  String get reorderItemRight => 'Move right';

  @override
  String get reorderItemToEnd => 'Move to the end';

  @override
  String get reorderItemToStart => 'Move to the start';

942 943 944 945 946 947
  @override
  String get expandedIconTapHint => 'Collapse';

  @override
  String get collapsedIconTapHint => 'Expand';

948 949 950
  @override
  String get refreshIndicatorSemanticLabel => 'Refresh';

951 952 953 954
  /// Creates an object that provides US English resource values for the material
  /// library widgets.
  ///
  /// The [locale] parameter is ignored.
955 956 957 958
  ///
  /// This method is typically used to create a [LocalizationsDelegate].
  /// The [MaterialApp] does so by default.
  static Future<MaterialLocalizations> load(Locale locale) {
959
    return SynchronousFuture<MaterialLocalizations>(const DefaultMaterialLocalizations());
960
  }
Yegor's avatar
Yegor committed
961

962 963 964 965
  /// A [LocalizationsDelegate] that uses [DefaultMaterialLocalizations.load]
  /// to create an instance of this class.
  ///
  /// [MaterialApp] automatically adds this value to [MaterialApp.localizationsDelegates].
966
  static const LocalizationsDelegate<MaterialLocalizations> delegate = _MaterialLocalizationsDelegate();
967 968 969 970 971 972 973 974 975 976 977 978

  @override
  String remainingTextFieldCharacterCount(int remaining) {
    switch (remaining) {
      case 0:
        return 'No characters remaining';
      case 1:
        return '1 character remaining';
      default:
        return '$remaining characters remaining';
    }
  }
Yegor's avatar
Yegor committed
979
}