Now the i18n system of day.dart contains the following keys:
- Months
- MonthsShort
- Weekdays
- WeekdaysShort
- WeekdaysMin
- AM
- PM
For example, let’s take a look at i18n/en.dart:
final Map<String, dynamic> Locale = {
'Name': 'en',
'Months': {
1: 'January',
2: 'February',
3: 'March',
4: 'April',
5: 'May',
6: 'June',
7: 'July',
8: 'August',
9: 'September',
10: 'October',
11: 'November',
12: 'December'
},
'Weekdays': {
1: 'Monday',
2: 'Tuesday',
3: 'Wednesday',
4: 'Thursday',
5: 'Friday',
6: 'Saturday',
7: 'Sunday'
},
'AM': 'AM',
'PM': 'PM',
'RelativeTime': {
'future': 'in %s',
'past': '%s ago',
's': 'a few seconds',
'm': 'a minute',
'mm': '%d minutes',
'h': 'an hour',
'hh': '%d hours',
'd': 'a day',
'dd': '%d days',
'M': 'a month',
'MM': '%d months',
'y': 'a year',
'yy': '%d years'
}
};
You can see many of keys like Months
, Weekdays
..., but where are the remained keys like MonthsShort
mentioned above?
Because the MonthsShort
is only a substring of the regular month string in English. So for example, the MonthsShort
of January
is Jan
, take between 0 and 3.
The WeekdaysShort
take between 0 and 3.
The WeekdaysMin
take between 0 and 2.
But in different languages, the Short of months and weekdays isn't fully the same as in English.
You can view other locale files like i18n/zh_cn.dart for more details.
For global usage:
import 'package:day/day.dart';
import 'package:day/i18n/zh_cn.dart' as zh_cn_locale;
void main() {
Day.locale(zh_cn_locale.locale);
final d = Day.fromString('2019-04-30T10:30:30.000Z');
}
For local usage:
import 'package:day/day.dart';
import 'package:day/i18n/zh_cn.dart' as zh_cn_locale;
void main() {
final d =
Day.fromString('2019-04-30T10:30:30.000Z').useLocale(zh_cn_locale.locale);
}
The local usage's priority is higher than the global usage.