This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
relative_date_localization.dart
92 lines (90 loc) · 2.99 KB
/
relative_date_localization.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/// Model class to describe all data required for localizing the formatted
/// [RelativeDateTime].
class RelativeDateLocalization {
final String languageCode;
final List<String> timeUnitsSingular;
final List<String> timeUnitsPlural;
final String prepositionPast;
final String prepositionFuture;
final String atTheMoment;
final List<FormatComponent> formatOrderPast;
final List<FormatComponent> formatOrderFuture;
/// Creates a [RelativeDateLocalization].
///
/// * [languageCode] is the language code of the current locale. The English localization
/// will be set to:
/// ```dart
/// languageCode: 'en'
/// ```
///
/// * [timeUnitsSingular] are the localized time units (singular form). The default English
/// localization will be set to:
/// ```dart
/// timeUnitsSingular: ['second', 'minute', 'hour', 'day', 'year'],
/// ```
///
/// * [timeUnitsPlural] are the localized time units (plural form). The default English
/// localization will be set to:
/// ```dart
/// timeUnitsPlural: ['seconds', 'minutes', 'hours', 'days', 'years'],
/// ```
///
/// * [prepositionPast] is the preposition to be displayed on relative dates in the past.
/// The default English localization will be set to:
/// ```dart
/// prepositionPast: 'ago',
/// ```
///
/// * [prepositionFuture] is the preposition to be displayed on relative dates in the future.
/// The default English localization will be set to:
/// ```dart
/// prepositionFuture: 'in',
/// ```
///
/// * [atTheMoment] is the localized string displayed if no difference in time can be measured.
/// The default English localization will be set to:
/// ```dart
/// atTheMoment: 'now',
/// ```
///
/// * [formatOrderPast] describes the order in which the preposition, the value and the unit
/// shall be displayed on the formatted string describing a date in the past.
/// The default English localization will be set to:
/// ```dart
/// formatOrderPast: [
/// FormatComponent.value,
/// FormatComponent.unit,
/// FormatComponent.preposition
/// ],
/// ```
///
/// * [formatOrderFuture] describes the order in which the preposition, the value and the unit
/// shall be displayed on the formatted string describing a date in the future.
/// The default English localization will be set to:
/// ```dart
/// formatOrderFuture: [
/// FormatComponent.preposition,
/// FormatComponent.value,
/// FormatComponent.unit,
/// ],
/// ```
const RelativeDateLocalization({
required this.languageCode,
required this.timeUnitsSingular,
required this.timeUnitsPlural,
required this.prepositionPast,
required this.prepositionFuture,
required this.atTheMoment,
required this.formatOrderPast,
required this.formatOrderFuture,
});
}
/// The sections of the formatted string
enum FormatComponent {
// The preposition to indicate whether the date is in the past or the future.
preposition,
// The time value.
value,
// The time unit.
unit,
}