Intl class

The Intl class provides a common entry point for internationalization related tasks. An Intl instance can be created for a particular locale and used to create a date format via anIntl.date(). Static methods on this class are also used in message formatting.

Examples: today(date) => Intl.message( "Today's date is $date", name: 'today', args: date, desc: 'Indicate the current date', examples: const {'date' : 'June 8, 2012'}); print(today(new DateTime.now().toString());

 howManyPeople(numberOfPeople, place) => Intl.plural(
       zero: 'I see no one at all',
       one: 'I see $numberOfPeople other person',
       other: 'I see $numberOfPeople other people')} in $place.''',
     name: 'msg',
     args: [numberOfPeople, place],
     desc: 'Description of how many people are seen in a place.',
     examples: const {'numberOfPeople': 3, 'place': 'London'});

Calling howManyPeople(2, 'Athens'); would produce "I see 2 other people in Athens." as output in the default locale. If run in a different locale it would produce appropriately translated output.

For more detailed information on messages and localizing them see the main package documentation

You can set the default locale. Intl.defaultLocale = "pt_BR";

To temporarily use a locale other than the default, use the withLocale function. var todayString = new DateFormat("pt_BR").format(new DateTime.now()); print(withLocale("pt_BR", () => today(todayString));

See tests/message_format_test.dart for more examples.

Constructors

Intl([String aLocale ])
Constructor optionally aLocale for specifics of the language locale to be used, otherwise, we will attempt to infer it (acceptable if Dart is running on the client, we can infer from the browser/client preferences).

Properties

locale String
Return the locale for this instance. If none was set, the locale will be the default.
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

date([String pattern, String desiredLocale ]) DateFormat
Return a new date format using the specified pattern. If desiredLocale is not specified, then we default to locale.
toString() String
Returns a string representation of this object.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited

Static Properties

defaultLocale String
The default locale. This defaults to being set from systemLocale, but can also be set explicitly, and will then apply to any new instances where the locale isn't specified. Note that a locale parameter to Intl.withLocale will supercede this value while that operation is active. Using Intl.withLocale may be preferable if you are using different locales in the same application.
read / write
systemLocale String
The system's locale, as obtained from the window.navigator.language or other operating system mechanism. Note that due to system limitations this is not automatically set, and must be set by importing one of intl_browser.dart or intl_standalone.dart and calling findSystemLocale().
read / write

Static Methods

canonicalizedLocale(String aLocale) String
Return the name aLocale turned into xx_YY where it might possibly be in the wrong case or with a hyphen instead of an underscore. If aLocale is null, for example, if you tried to get it from IE, return the current system locale.
gender(String targetGender, { String female, String male, String other, String desc, Map<String, dynamic> examples, String locale, String name, List args, String meaning, bool skip }) String
Format a message differently depending on targetGender.
genderLogic(String targetGender, { dynamic female, dynamic male, dynamic other, String locale }) → dynamic
Internal: Implements the logic for gender selection - use gender for normal messages.
getCurrentLocale() String
Accessor for the current locale. This should always == the default locale, unless for some reason this gets called inside a message that resets the locale.
message(String message_str, { String desc: '', Map<String, dynamic> examples: const {}, String locale, String name, List args, String meaning, bool skip }) String
Use this for a message that will be translated for different locales. The expected usage is that this is inside an enclosing function that only returns the value of this call and provides a scope for the variables that will be substituted in the message. [...]
plural(int howMany, { String zero, String one, String two, String few, String many, String other, String desc, Map<String, dynamic> examples, String locale, String name, List args, String meaning, bool skip }) String
Format a message differently depending on howMany. Normally used as part of an Intl.message text that is to be translated. Selects the correct plural form from the provided alternatives. The other named argument is mandatory.
pluralLogic(int howMany, { dynamic zero, dynamic one, dynamic two, dynamic few, dynamic many, dynamic other, String locale, String meaning }) → dynamic
Internal: Implements the logic for plural selection - use plural for normal messages.
select(Object choice, Map<String, String> cases, { String desc, Map<String, dynamic> examples, String locale, String name, List args, String meaning, bool skip }) String
Format a message differently depending on choice. We look up the value of choice in cases and return the result, or an empty string if it is not found. Normally used as part of an Intl.message message that is to be translated.
selectLogic(Object choice, Map<String, dynamic> cases) → dynamic
Internal: Implements the logic for select - use select for normal messages.
shortLocale(String aLocale) String
Return the short version of a locale name, e.g. 'en_US' => 'en'
verifiedLocale(String newLocale, Function localeExists, { Function onFailure: _throwLocaleError }) String
Given newLocale return a locale that we have data for that is similar to it, if possible. [...]
withLocale(String locale, dynamic function()) → dynamic
Run function with the default locale set to locale and return the result. [...]