Skip to content
43 changes: 43 additions & 0 deletions I18N.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# I18n

- [Introduction](#introduction)
- [Month forms in dates](#month-forms-in-dates)
- [Relative time forms](#relative-time-forms)
- [How to use](#how-to-use)
- [Locale data conventions](#locale-data-conventions)

## Introduction

Now the i18n system of day.dart contains the following keys:

- Months
- MonthsShort
- MonthsFormat (optional)
- MonthsShortFormat (optional)
- Weekdays
- WeekdaysShort
- WeekdaysMin
- AM
- PM
- RelativeTime

For example, let’s take a look at [i18n/en.dart](https://github.com/dayjs/day.dart/blob/master/lib/i18n/en.dart):

Expand Down Expand Up @@ -75,6 +81,33 @@ But in different languages, the **Short** of months and weekdays isn't fully the

You can view other locale files like [i18n/zh_cn.dart](https://github.com/dayjs/day.dart/blob/master/lib/i18n/zh_cn.dart) for more details.

### Month forms in dates

Locales can provide optional `MonthsFormat` and `MonthsShortFormat` maps,
indexed from 1 to 12. These forms are used for `MMMM` and `MMM` when the
month token immediately follows `D` or `DD`, separated by whitespace or
bracketed literal text. Otherwise, `Months` and `MonthsShort` are used.
Locales without these optional maps keep their existing behavior.

These two optional maps are currently used only for Russian month forms.

For example, Russian `MMMM` displays `апрель`, while `D MMMM YYYY` displays
`30 апреля 2019`. `D [day] MMMM` also uses the date form; `[D] MMMM` does not,
because the day token is escaped.

### Relative time forms

With the relative time plugin, unit entries in `RelativeTime` can be strings
or callbacks with the signature `String Function(int count, bool withoutSuffix)`.
The callback returns a template; `%d` is replaced with the absolute count.
`withoutSuffix` is true when the optional boolean argument to `from`, `to`,
`fromNow`, or `toNow` is true. The `future` and `past` entries remain strings
containing `%s`.

For example, Russian uses `минута` without a suffix, but `минуту` in
`через минуту` and `минуту назад`. German similarly uses `eine Minute` on
its own and `einer Minute` in `in einer Minute` or `vor einer Minute`.

## How To Use

For global usage:
Expand Down Expand Up @@ -103,3 +136,13 @@ void main() {
```

The local usage's priority is higher than the global usage.

## Locale data conventions

Locale data follows [Unicode CLDR](https://cldr.unicode.org/translation/date-time/date-time-names)
conventions for each language and region, including spelling, capitalization,
abbreviation punctuation, and spacing.

Relative times use natural expressions such as "a few seconds" and "a minute".
Existing localized expressions are retained where CLDR does not provide a
translation.
81 changes: 81 additions & 0 deletions lib/i18n/de.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
final Map<String, dynamic> locale = {
'Name': 'de',
'Months': {
1: 'Januar',
2: 'Februar',
3: 'März',
4: 'April',
5: 'Mai',
6: 'Juni',
7: 'Juli',
8: 'August',
9: 'September',
10: 'Oktober',
11: 'November',
12: 'Dezember'
},
'MonthsShort': {
1: 'Jan.',
2: 'Feb.',
3: 'März',
4: 'Apr.',
5: 'Mai',
6: 'Juni',
7: 'Juli',
8: 'Aug.',
9: 'Sept.',
10: 'Okt.',
11: 'Nov.',
12: 'Dez.'
},
'Weekdays': {
1: 'Montag',
2: 'Dienstag',
3: 'Mittwoch',
4: 'Donnerstag',
5: 'Freitag',
6: 'Samstag',
7: 'Sonntag'
},
'WeekdaysShort': {
1: 'Mo.',
2: 'Di.',
3: 'Mi.',
4: 'Do.',
5: 'Fr.',
6: 'Sa.',
7: 'So.'
},
'WeekdaysMin': {
1: 'Mo.',
2: 'Di.',
3: 'Mi.',
4: 'Do.',
5: 'Fr.',
6: 'Sa.',
7: 'So.'
},
'AM': 'AM',
'PM': 'PM',
'RelativeTime': {
'future': 'in %s',
'past': 'vor %s',
's': 'ein paar Sekunden',
'm': (int n, bool withoutSuffix) =>
withoutSuffix ? 'eine Minute' : 'einer Minute',
'mm': '%d Minuten',
'h': (int n, bool withoutSuffix) =>
withoutSuffix ? 'eine Stunde' : 'einer Stunde',
'hh': '%d Stunden',
'd': (int n, bool withoutSuffix) => withoutSuffix ? 'ein Tag' : 'einem Tag',
'dd': (int n, bool withoutSuffix) => withoutSuffix ? '%d Tage' : '%d Tagen',
'M': (int n, bool withoutSuffix) =>
withoutSuffix ? 'ein Monat' : 'einem Monat',
'MM': (int n, bool withoutSuffix) =>
withoutSuffix ? '%d Monate' : '%d Monaten',
'y': (int n, bool withoutSuffix) =>
withoutSuffix ? 'ein Jahr' : 'einem Jahr',
'yy': (int n, bool withoutSuffix) =>
withoutSuffix ? '%d Jahre' : '%d Jahren'
}
};
75 changes: 75 additions & 0 deletions lib/i18n/es.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
final Map<String, dynamic> locale = {
'Name': 'es',
'Months': {
1: 'enero',
2: 'febrero',
3: 'marzo',
4: 'abril',
5: 'mayo',
6: 'junio',
7: 'julio',
8: 'agosto',
9: 'septiembre',
10: 'octubre',
11: 'noviembre',
12: 'diciembre'
},
'MonthsShort': {
1: 'ene',
2: 'feb',
3: 'mar',
4: 'abr',
5: 'may',
6: 'jun',
7: 'jul',
8: 'ago',
9: 'sept',
10: 'oct',
11: 'nov',
12: 'dic'
},
'Weekdays': {
1: 'lunes',
2: 'martes',
3: 'miércoles',
4: 'jueves',
5: 'viernes',
6: 'sábado',
7: 'domingo'
},
'WeekdaysShort': {
1: 'lun',
2: 'mar',
3: 'mié',
4: 'jue',
5: 'vie',
6: 'sáb',
7: 'dom'
},
'WeekdaysMin': {
1: 'LU',
2: 'MA',
3: 'MI',
4: 'JU',
5: 'VI',
6: 'SA',
7: 'DO'
},
'AM': 'a.\u202fm.',
'PM': 'p.\u202fm.',
'RelativeTime': {
'future': 'dentro de %s',
'past': 'hace %s',
's': 'unos segundos',
'm': 'un minuto',
'mm': '%d minutos',
'h': 'una hora',
'hh': '%d horas',
'd': 'un día',
'dd': '%d días',
'M': 'un mes',
'MM': '%d meses',
'y': 'un año',
'yy': '%d años'
}
};
75 changes: 75 additions & 0 deletions lib/i18n/fr.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
final Map<String, dynamic> locale = {
'Name': 'fr',
'Months': {
1: 'janvier',
2: 'février',
3: 'mars',
4: 'avril',
5: 'mai',
6: 'juin',
7: 'juillet',
8: 'août',
9: 'septembre',
10: 'octobre',
11: 'novembre',
12: 'décembre'
},
'MonthsShort': {
1: 'janv.',
2: 'févr.',
3: 'mars',
4: 'avr.',
5: 'mai',
6: 'juin',
7: 'juil.',
8: 'août',
9: 'sept.',
10: 'oct.',
11: 'nov.',
12: 'déc.'
},
'Weekdays': {
1: 'lundi',
2: 'mardi',
3: 'mercredi',
4: 'jeudi',
5: 'vendredi',
6: 'samedi',
7: 'dimanche'
},
'WeekdaysShort': {
1: 'lun.',
2: 'mar.',
3: 'mer.',
4: 'jeu.',
5: 'ven.',
6: 'sam.',
7: 'dim.'
},
'WeekdaysMin': {
1: 'lu',
2: 'ma',
3: 'me',
4: 'je',
5: 've',
6: 'sa',
7: 'di'
},
'AM': 'AM',
'PM': 'PM',
'RelativeTime': {
'future': 'dans %s',
'past': 'il y a %s',
's': 'quelques secondes',
'm': 'une minute',
'mm': '%d minutes',
'h': 'une heure',
'hh': '%d heures',
'd': 'un jour',
'dd': '%d jours',
'M': 'un mois',
'MM': '%d mois',
'y': 'un an',
'yy': '%d ans'
}
};
59 changes: 59 additions & 0 deletions lib/i18n/ja.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
final Map<String, dynamic> locale = {
'Name': 'ja',
'Months': {
1: '1月',
2: '2月',
3: '3月',
4: '4月',
5: '5月',
6: '6月',
7: '7月',
8: '8月',
9: '9月',
10: '10月',
11: '11月',
12: '12月'
},
'MonthsShort': {
1: '1月',
2: '2月',
3: '3月',
4: '4月',
5: '5月',
6: '6月',
7: '7月',
8: '8月',
9: '9月',
10: '10月',
11: '11月',
12: '12月'
},
'Weekdays': {
1: '月曜日',
2: '火曜日',
3: '水曜日',
4: '木曜日',
5: '金曜日',
6: '土曜日',
7: '日曜日'
},
'WeekdaysShort': {1: '月', 2: '火', 3: '水', 4: '木', 5: '金', 6: '土', 7: '日'},
'WeekdaysMin': {1: '月', 2: '火', 3: '水', 4: '木', 5: '金', 6: '土', 7: '日'},
'AM': '午前',
'PM': '午後',
'RelativeTime': {
'future': '%s後',
'past': '%s前',
's': '数秒',
'm': '1 分',
'mm': '%d 分',
'h': '1 時間',
'hh': '%d 時間',
'd': '1 日',
'dd': '%d 日',
'M': '1 か月',
'MM': '%d か月',
'y': '1 年',
'yy': '%d 年'
}
};
Loading
Loading