@@ -23,7 +23,7 @@ You can explicitly set the global locale
23
23
24
24
or get it from the browser
25
25
26
- import " package:intl/intl_browser.dart" ;
26
+ import ' package:intl/intl_browser.dart' ;
27
27
...
28
28
findSystemLocale().then(runTheRestOfMyProgram);
29
29
@@ -43,8 +43,8 @@ a specific locale, pass in the locale as a parameter to methods, or
43
43
set the default locale.
44
44
45
45
``` dart
46
- var format = new DateFormat.yMd("ar" );
47
- var dateString = format.format(new DateTime.now());
46
+ var format = DateFormat.yMd('ar' );
47
+ var dateString = format.format(DateTime.now());
48
48
```
49
49
50
50
or
@@ -56,8 +56,8 @@ print(myMessage(dateString, locale: 'ar');
56
56
or
57
57
58
58
``` dart
59
- Intl.defaultLocale = "es" ;
60
- new DateFormat.jm().format(new DateTime.now());
59
+ Intl.defaultLocale = 'es' ;
60
+ DateFormat.jm().format(DateTime.now());
61
61
```
62
62
63
63
## Initialization
@@ -85,11 +85,11 @@ Messages to be localized are written as functions that return the result of
85
85
an [ Intl.message] [ Intl.message ] call.
86
86
87
87
String continueMessage() => Intl.message(
88
- " Hit any key to continue" ,
89
- name: " continueMessage" ,
88
+ ' Hit any key to continue' ,
89
+ name: ' continueMessage' ,
90
90
args: [],
91
- desc: " Explains that we will not proceed further until "
92
- " the user presses a key" );
91
+ desc: ' Explains that we will not proceed further until '
92
+ ' the user presses a key' );
93
93
print(continueMessage());
94
94
95
95
This provides, in addition to the basic message string, a name, a description
@@ -118,11 +118,11 @@ the formatting outside the function and pass the formatted string into
118
118
the message.
119
119
120
120
greetingMessage(name) => Intl.message(
121
- " Hello $name!" ,
122
- name: " greetingMessage" ,
121
+ ' Hello $name!' ,
122
+ name: ' greetingMessage' ,
123
123
args: [name],
124
- desc: " Greet the user as they first open the application" ,
125
- examples: const {'name': " Emily" });
124
+ desc: ' Greet the user as they first open the application' ,
125
+ examples: const {'name': ' Emily' });
126
126
print(greetingMessage('Dan'));
127
127
128
128
There is one special class of complex expressions allowed in the
@@ -134,12 +134,12 @@ message string, for plurals and genders.
134
134
zero: 'There are no emails left for $userName.',
135
135
one: 'There is $howMany email left for $userName.',
136
136
other: 'There are $howMany emails left for $userName.')}''',
137
- name: " remainingEmailsMessage" ,
137
+ name: ' remainingEmailsMessage' ,
138
138
args: [howMany, userName],
139
- desc: " How many emails remain after archiving." ,
139
+ desc: How many emails remain after archiving.' ,
140
140
examples: const {'howMany': 42, 'userName': 'Fred'});
141
141
142
- print(remainingEmailsMessage(1, " Fred" ));
142
+ print(remainingEmailsMessage(1, ' Fred' ));
143
143
144
144
However, since the typical usage for a plural or gender is for it to
145
145
be at the top-level, we can also omit the [ Intl.message] [ Intl.message ] call and
@@ -151,9 +151,9 @@ provide its parameters to the [Intl.plural][Intl.plural] call instead.
151
151
zero: 'There are no emails left for $userName.',
152
152
one: 'There is $howMany email left for $userName.',
153
153
other: 'There are $howMany emails left for $userName.',
154
- name: " remainingEmailsMessage" ,
154
+ name: ' remainingEmailsMessage' ,
155
155
args: [howMany, userName],
156
- desc: " How many emails remain after archiving." ,
156
+ desc: ' How many emails remain after archiving.' ,
157
157
examples: const {'howMany': 42, 'userName': 'Fred'});
158
158
159
159
Similarly, there is an [ Intl.gender] [ Intl.gender ] message, and plurals
@@ -165,9 +165,9 @@ and genders can be nested.
165
165
male: '$userName is unavailable because he is not online.',
166
166
female: '$userName is unavailable because she is not online.',
167
167
other: '$userName is unavailable because they are not online',
168
- name: " notOnlineMessage" ,
168
+ name: ' notOnlineMessage' ,
169
169
args: [userName, userGender],
170
- desc: " The user is not available to hangout." ,
170
+ desc: ' The user is not available to hangout.' ,
171
171
examples: const {{'userGender': 'male', 'userName': 'Fred'},
172
172
{'userGender': 'female', 'userName' : 'Alice'}});
173
173
@@ -209,9 +209,9 @@ for a specific locale. Once that's done, any
209
209
will automatically print the translated version instead of the
210
210
original.
211
211
212
- import " my_prefix_messages_all.dart" ;
212
+ import ' my_prefix_messages_all.dart' ;
213
213
...
214
- initializeMessages("dk" ).then(printSomeMessages);
214
+ initializeMessages('dk' ).then(printSomeMessages);
215
215
216
216
Once the future returned from the initialization call returns, the
217
217
message data is available.
@@ -220,7 +220,7 @@ message data is available.
220
220
221
221
To format a number, create a NumberFormat instance.
222
222
223
- var f = new NumberFormat(" ###.0#", " en_US" );
223
+ var f = NumberFormat(' ###.0#', ' en_US' );
224
224
print(f.format(12.345));
225
225
==> 12.34
226
226
@@ -246,22 +246,22 @@ instance. These can be created using a set of commonly used skeletons
246
246
taken from ICU/CLDR or using an explicit pattern. For details on the
247
247
supported skeletons and patterns see [ DateFormat] [ DateFormat ] .
248
248
249
- new DateFormat.yMMMMEEEEd().format(aDateTime);
249
+ DateFormat.yMMMMEEEEd().format(aDateTime);
250
250
==> 'Wednesday, January 10, 2012'
251
- new DateFormat(" EEEEE", " en_US" ).format(aDateTime);
251
+ DateFormat(' EEEEE', ' en_US' ).format(aDateTime);
252
252
==> 'Wednesday'
253
- new DateFormat(" EEEEE", "ln" ).format(aDateTime);
253
+ DateFormat(' EEEEE', 'ln' ).format(aDateTime);
254
254
==> 'mokɔlɔ mwa mísáto'
255
255
256
256
You can also parse dates using the same skeletons or patterns.
257
257
258
- new DateFormat.yMd(" en_US" ).parse(" 1/10/2012" );
259
- new DateFormat(" Hms", " en_US" ).parse('14:23:01');
258
+ DateFormat.yMd(' en_US' ).parse(' 1/10/2012' );
259
+ DateFormat(' Hms', ' en_US' ).parse('14:23:01');
260
260
261
261
Skeletons can be combined, the main use being to print a full date and
262
262
time, e.g.
263
263
264
- new DateFormat.yMEd().add_jms().format(new DateTime.now());
264
+ DateFormat.yMEd().add_jms().format(DateTime.now());
265
265
==> 'Thu, 5/23/2013 10:21:47 AM'
266
266
267
267
Known limitations: Time zones are not yet supported. Dart
@@ -273,7 +273,7 @@ locale, you must load the appropriate data by calling.
273
273
274
274
import 'package:intl/date_symbol_data_local.dart';
275
275
...
276
- initializeDateFormatting(" de_DE" , null).then(formatDates);
276
+ initializeDateFormatting(' de_DE' , null).then(formatDates);
277
277
278
278
Once the future returned from the initialization call returns, the
279
279
formatting data is available.
@@ -293,8 +293,8 @@ direction. The direction can be specified with the
293
293
[ RTL] [ BidiFormatter.RTL ] and [ LTR] [ BidiFormatter.LTR ] constructors, or
294
294
detected from the text.
295
295
296
- new BidiFormatter.RTL().wrapWithUnicode('xyz');
297
- new BidiFormatter.RTL().wrapWithSpan('xyz');
296
+ BidiFormatter.RTL().wrapWithUnicode('xyz');
297
+ BidiFormatter.RTL().wrapWithSpan('xyz');
298
298
299
299
[ intl_lib ] : https://www.dartdocs.org/documentation/intl/latest/intl/intl-library.html
300
300
[ Intl ] : https://www.dartdocs.org/documentation/intl/latest
0 commit comments