YSLocalization.dart 3.9 KB

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