import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; class MyLocalizationsDelegate extends LocalizationsDelegate { const MyLocalizationsDelegate(); @override bool isSupported(Locale locale) => locale.languageCode == 'zh'; @override Future load(Locale locale) => ZhCupertinoLocalizations.load(locale); @override bool shouldReload(MyLocalizationsDelegate old) => false; @override String toString() => 'DefaultCupertinoLocalizations.delegate(zh)'; } class ZhCupertinoLocalizations implements CupertinoLocalizations { const ZhCupertinoLocalizations(); static const List _shortWeekdays = [ '周一', '周二', '周三', '周四', '周五', '周六', '周日', ]; static const List _shortMonths = [ '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', ]; static const List _months = [ '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', ]; @override String datePickerYear(int yearIndex) => yearIndex.toString(); @override String datePickerMonth(int monthIndex) => _months[monthIndex - 1]; @override String datePickerDayOfMonth(int dayIndex) => dayIndex.toString(); @override String datePickerHour(int hour) => hour.toString(); @override String datePickerHourSemanticsLabel(int hour) => hour.toString() + " o'clock"; @override String datePickerMinute(int minute) => minute.toString().padLeft(2, '0'); @override String datePickerMinuteSemanticsLabel(int minute) { if (minute == 1) return '1 分'; return minute.toString() + ' 分'; } @override String datePickerMediumDate(DateTime date) { return '${_shortWeekdays[date.weekday - DateTime.monday]} ' '${_shortMonths[date.month - DateTime.january]} ' '${date.day.toString().padRight(2)}'; } @override DatePickerDateOrder get datePickerDateOrder => DatePickerDateOrder.mdy; @override DatePickerDateTimeOrder get datePickerDateTimeOrder => DatePickerDateTimeOrder.date_time_dayPeriod; @override String get anteMeridiemAbbreviation => '上午'; @override String get postMeridiemAbbreviation => '下午'; @override String get todayLabel => '今天'; @override String get alertDialogLabel => 'Alert'; @override String timerPickerHour(int hour) => hour.toString(); @override String timerPickerMinute(int minute) => minute.toString(); @override String timerPickerSecond(int second) => second.toString(); @override String timerPickerHourLabel(int hour) => hour == 1 ? '小时' : '小时'; @override String timerPickerMinuteLabel(int minute) => '分.'; @override String timerPickerSecondLabel(int second) => '秒.'; @override String get cutButtonLabel => '剪贴'; @override String get copyButtonLabel => '拷贝'; @override String get pasteButtonLabel => '粘贴'; @override String get selectAllButtonLabel => '选择全部'; static Future load(Locale locale) { return SynchronousFuture( const ZhCupertinoLocalizations()); } /// A [LocalizationsDelegate] that uses [DefaultCupertinoLocalizations.load] /// to create an instance of this class. static const LocalizationsDelegate delegate = MyLocalizationsDelegate(); @override // TODO: implement modalBarrierDismissLabel String get modalBarrierDismissLabel => ''; @override // TODO: implement searchTextFieldPlaceholerLabel String get searchTextFieldPlaceholerLabel => ''; @override String tabSemanticsLabel({int tabIndex, int tabCount}) { return ''; } @override // TODO: implement timerPickerHourLabels List get timerPickerHourLabels => []; @override // TODO: implement timerPickerMinuteLabels List get timerPickerMinuteLabels => []; @override // TODO: implement timerPickerSecondLabels List get timerPickerSecondLabels => []; @override // TODO: implement searchTextFieldPlaceholderLabel String get searchTextFieldPlaceholderLabel => ''; }