YSLocalizationsDelegate.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/foundation.dart';
  3. class MyLocalizationsDelegate
  4. extends LocalizationsDelegate<CupertinoLocalizations> {
  5. const MyLocalizationsDelegate();
  6. @override
  7. bool isSupported(Locale locale) => locale.languageCode == 'zh';
  8. @override
  9. Future<CupertinoLocalizations> load(Locale locale) =>
  10. ZhCupertinoLocalizations.load(locale);
  11. @override
  12. bool shouldReload(MyLocalizationsDelegate old) => false;
  13. @override
  14. String toString() => 'DefaultCupertinoLocalizations.delegate(zh)';
  15. }
  16. class ZhCupertinoLocalizations implements CupertinoLocalizations {
  17. const ZhCupertinoLocalizations();
  18. static const List<String> _shortWeekdays = <String>[
  19. '周一',
  20. '周二',
  21. '周三',
  22. '周四',
  23. '周五',
  24. '周六',
  25. '周日',
  26. ];
  27. static const List<String> _shortMonths = <String>[
  28. '1月',
  29. '2月',
  30. '3月',
  31. '4月',
  32. '5月',
  33. '6月',
  34. '7月',
  35. '8月',
  36. '9月',
  37. '10月',
  38. '11月',
  39. '12月',
  40. ];
  41. static const List<String> _months = <String>[
  42. '1月',
  43. '2月',
  44. '3月',
  45. '4月',
  46. '5月',
  47. '6月',
  48. '7月',
  49. '8月',
  50. '9月',
  51. '10月',
  52. '11月',
  53. '12月',
  54. ];
  55. @override
  56. String datePickerYear(int yearIndex) => yearIndex.toString();
  57. @override
  58. String datePickerMonth(int monthIndex) => _months[monthIndex - 1];
  59. @override
  60. String datePickerDayOfMonth(int dayIndex) => dayIndex.toString();
  61. @override
  62. String datePickerHour(int hour) => hour.toString();
  63. @override
  64. String datePickerHourSemanticsLabel(int hour) => hour.toString() + " o'clock";
  65. @override
  66. String datePickerMinute(int minute) => minute.toString().padLeft(2, '0');
  67. @override
  68. String datePickerMinuteSemanticsLabel(int minute) {
  69. if (minute == 1) return '1 分';
  70. return minute.toString() + ' 分';
  71. }
  72. @override
  73. String datePickerMediumDate(DateTime date) {
  74. return '${_shortWeekdays[date.weekday - DateTime.monday]} '
  75. '${_shortMonths[date.month - DateTime.january]} '
  76. '${date.day.toString().padRight(2)}';
  77. }
  78. @override
  79. DatePickerDateOrder get datePickerDateOrder => DatePickerDateOrder.mdy;
  80. @override
  81. DatePickerDateTimeOrder get datePickerDateTimeOrder =>
  82. DatePickerDateTimeOrder.date_time_dayPeriod;
  83. @override
  84. String get anteMeridiemAbbreviation => '上午';
  85. @override
  86. String get postMeridiemAbbreviation => '下午';
  87. @override
  88. String get todayLabel => '今天';
  89. @override
  90. String get alertDialogLabel => 'Alert';
  91. @override
  92. String timerPickerHour(int hour) => hour.toString();
  93. @override
  94. String timerPickerMinute(int minute) => minute.toString();
  95. @override
  96. String timerPickerSecond(int second) => second.toString();
  97. @override
  98. String timerPickerHourLabel(int hour) => hour == 1 ? '小时' : '小时';
  99. @override
  100. String timerPickerMinuteLabel(int minute) => '分.';
  101. @override
  102. String timerPickerSecondLabel(int second) => '秒.';
  103. @override
  104. String get cutButtonLabel => '剪贴';
  105. @override
  106. String get copyButtonLabel => '拷贝';
  107. @override
  108. String get pasteButtonLabel => '粘贴';
  109. @override
  110. String get selectAllButtonLabel => '选择全部';
  111. static Future<CupertinoLocalizations> load(Locale locale) {
  112. return SynchronousFuture<CupertinoLocalizations>(
  113. const ZhCupertinoLocalizations());
  114. }
  115. /// A [LocalizationsDelegate] that uses [DefaultCupertinoLocalizations.load]
  116. /// to create an instance of this class.
  117. static const LocalizationsDelegate<CupertinoLocalizations> delegate =
  118. MyLocalizationsDelegate();
  119. @override
  120. // TODO: implement modalBarrierDismissLabel
  121. String get modalBarrierDismissLabel => '';
  122. @override
  123. // TODO: implement searchTextFieldPlaceholerLabel
  124. String get searchTextFieldPlaceholerLabel => '';
  125. @override
  126. String tabSemanticsLabel({int tabIndex, int tabCount}) {
  127. return '';
  128. }
  129. @override
  130. // TODO: implement timerPickerHourLabels
  131. List<String> get timerPickerHourLabels => [];
  132. @override
  133. // TODO: implement timerPickerMinuteLabels
  134. List<String> get timerPickerMinuteLabels => [];
  135. @override
  136. // TODO: implement timerPickerSecondLabels
  137. List<String> get timerPickerSecondLabels => [];
  138. @override
  139. // TODO: implement searchTextFieldPlaceholderLabel
  140. String get searchTextFieldPlaceholderLabel => '';
  141. }