CupertinoLocalizationsDelegate.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import 'package:flutter/foundation.dart' show SynchronousFuture;
  2. import 'package:flutter/cupertino.dart';
  3. class CupertinoLocalizationsDelegate
  4. extends LocalizationsDelegate<CupertinoLocalizations> {
  5. const CupertinoLocalizationsDelegate();
  6. @override
  7. bool isSupported(Locale locale) =>
  8. <String>['en', 'zh'].contains(locale.languageCode);
  9. @override
  10. SynchronousFuture<_DefaultCupertinoLocalizations> load(Locale locale) {
  11. return SynchronousFuture<_DefaultCupertinoLocalizations>(
  12. _DefaultCupertinoLocalizations(locale.languageCode));
  13. }
  14. @override
  15. bool shouldReload(CupertinoLocalizationsDelegate old) => false;
  16. }
  17. class _DefaultCupertinoLocalizations extends CupertinoLocalizations {
  18. _DefaultCupertinoLocalizations(this._languageCode)
  19. : assert(_languageCode != null);
  20. final DefaultCupertinoLocalizations _en =
  21. const DefaultCupertinoLocalizations();
  22. final String _languageCode;
  23. final Map<String, Map<String, String>> _dict = <String, Map<String, String>>{
  24. 'en': <String, String>{
  25. 'alert': 'Alert',
  26. 'copy': 'Copy',
  27. 'paste': 'Paste',
  28. 'cut': 'Cut',
  29. 'selectAll': 'Select all',
  30. 'today': 'today'
  31. },
  32. 'zh': <String, String>{
  33. 'alert': '警告',
  34. 'copy': '复制',
  35. 'paste': '粘贴',
  36. 'cut': '剪切',
  37. 'selectAll': '选择全部',
  38. 'today': '今天'
  39. }
  40. };
  41. @override
  42. String get alertDialogLabel => _get('alert');
  43. @override
  44. String get anteMeridiemAbbreviation => _en.anteMeridiemAbbreviation;
  45. @override
  46. String get postMeridiemAbbreviation => _en.postMeridiemAbbreviation;
  47. @override
  48. String get copyButtonLabel => _get('copy');
  49. @override
  50. String get cutButtonLabel => _get('cut');
  51. @override
  52. String get pasteButtonLabel => _get('paste');
  53. @override
  54. String get selectAllButtonLabel => _get('selectAll');
  55. @override
  56. DatePickerDateOrder get datePickerDateOrder => _en.datePickerDateOrder;
  57. @override
  58. DatePickerDateTimeOrder get datePickerDateTimeOrder =>
  59. _en.datePickerDateTimeOrder;
  60. @override
  61. String datePickerDayOfMonth(int dayIndex) =>
  62. _en.datePickerDayOfMonth(dayIndex);
  63. @override
  64. String datePickerHour(int hour) => _en.datePickerHour(hour);
  65. @override
  66. String datePickerHourSemanticsLabel(int hour) =>
  67. _en.datePickerHourSemanticsLabel(hour);
  68. @override
  69. String datePickerMediumDate(DateTime date) => _en.datePickerMediumDate(date);
  70. @override
  71. String datePickerMinute(int minute) => _en.datePickerMinute(minute);
  72. @override
  73. String datePickerMinuteSemanticsLabel(int minute) =>
  74. _en.datePickerMinuteSemanticsLabel(minute);
  75. @override
  76. String datePickerMonth(int monthIndex) => _en.datePickerMonth(monthIndex);
  77. @override
  78. String datePickerYear(int yearIndex) => _en.datePickerYear(yearIndex);
  79. @override
  80. String timerPickerHour(int hour) => _en.timerPickerHour(hour);
  81. @override
  82. String timerPickerHourLabel(int hour) => _en.timerPickerHourLabel(hour);
  83. @override
  84. String timerPickerMinute(int minute) => _en.timerPickerMinute(minute);
  85. @override
  86. String timerPickerMinuteLabel(int minute) =>
  87. _en.timerPickerMinuteLabel(minute);
  88. @override
  89. String timerPickerSecond(int second) => _en.timerPickerSecond(second);
  90. @override
  91. String timerPickerSecondLabel(int second) =>
  92. _en.timerPickerSecondLabel(second);
  93. String _get(String key) {
  94. return _dict[_languageCode]?[key]?? "";
  95. }
  96. @override
  97. String get todayLabel => _get("today");
  98. @override
  99. String get modalBarrierDismissLabel => _en.modalBarrierDismissLabel;
  100. @override
  101. String get searchTextFieldPlaceholderLabel => _en.searchTextFieldPlaceholderLabel;
  102. @override
  103. String tabSemanticsLabel({required int tabIndex, required int tabCount}) => _en.tabSemanticsLabel(tabIndex: tabIndex, tabCount: tabCount);
  104. @override
  105. List<String> get timerPickerHourLabels => _en.timerPickerHourLabels;
  106. @override
  107. List<String> get timerPickerMinuteLabels => _en.timerPickerMinuteLabels;
  108. @override
  109. List<String> get timerPickerSecondLabels => _en.timerPickerSecondLabels;
  110. }