### Format a Number with a Specific Pattern Source: https://github.com/dart-lang/intl/blob/master/README.md Create a NumberFormat instance with a pattern and locale to format numbers. The example shows formatting to two decimal places. ```dart var f = NumberFormat('###.0#', 'en_US'); print(f.format(12.345)); ==> 12.35 ``` -------------------------------- ### Format Date with Skeleton Source: https://github.com/dart-lang/intl/blob/master/README.md Format a DateTime object using a predefined skeleton for common date representations. The example uses the yMMMMEEEEd skeleton. ```dart DateFormat.yMMMMEEEEd().format(aDateTime); ==> 'Wednesday, January 10, 2012' ``` -------------------------------- ### Combine Date and Time Skeletons for Formatting Source: https://github.com/dart-lang/intl/blob/master/README.md Combine multiple date and time skeletons to format a DateTime object. This example combines a full date skeleton with a time skeleton. ```dart DateFormat.yMEd().add_jms().format(DateTime.now()); ==> 'Thu, 5/23/2013 10:21:47 AM' ``` -------------------------------- ### Parse Date with Skeleton Source: https://github.com/dart-lang/intl/blob/master/README.md Parse a date string into a DateTime object using a skeleton. The example uses the yMd skeleton for parsing '1/10/2012'. ```dart DateFormat.yMd('en_US').parse('1/10/2012'); ``` -------------------------------- ### Format Date with Explicit Pattern and Locale Source: https://github.com/dart-lang/intl/blob/master/README.md Format a DateTime object using an explicit pattern string and locale. The example uses 'EEEEE' for the full day of the week name. ```dart DateFormat('EEEEE', 'en_US').format(aDateTime); ==> 'Wednesday' ``` -------------------------------- ### Format Date with Non-English Locale Source: https://github.com/dart-lang/intl/blob/master/README.md Format a DateTime object using a pattern and a non-English locale. The example shows formatting the day of the week in Lingala. ```dart DateFormat('EEEEE', 'ln').format(aDateTime); ==> 'mokɔlɔ mwa mísáto' ``` -------------------------------- ### Parse Date with Explicit Pattern Source: https://github.com/dart-lang/intl/blob/master/README.md Parse a date string into a DateTime object using an explicit pattern. The example uses the Hms pattern for parsing time. ```dart DateFormat('Hms', 'en_US').parse('14:23:01'); ``` -------------------------------- ### Initialize Messages for a Locale Source: https://github.com/dart-lang/intl/blob/master/README.md Import the generated `messages_all.dart` file and call `initializeMessages` with the desired locale code. This prepares the application to use translated messages for that locale. The initialization returns a future that completes when the message data is ready. ```dart import 'my_prefix_messages_all.dart'; ... initializeMessages('dk').then(printSomeMessages); ``` -------------------------------- ### Initialize Date Formatting Data for a Locale Source: https://github.com/dart-lang/intl/blob/master/README.md Load locale-specific date formatting data before performing any DateTime formatting. This is required for non-default locales. ```dart import 'package:intl/date_symbol_data_local.dart'; ... initializeDateFormatting('de_DE', null).then(formatDates); ``` -------------------------------- ### Define a Basic Message Source: https://github.com/dart-lang/intl/blob/master/README.md Use Intl.message to define a simple, translatable string. The 'name' parameter should match the function name. ```dart String continueMessage() => Intl.message( 'Hit any key to continue', name: 'continueMessage', args: [], desc: 'Explains that we will not proceed further until ' 'the user presses a key'); print(continueMessage()); ``` -------------------------------- ### Find System Locale Source: https://github.com/dart-lang/intl/blob/master/README.md Asynchronously find the system's default locale. This is useful for setting the locale dynamically from the browser environment. ```dart import 'package:intl/intl_browser.dart'; ... findSystemLocale().then(runTheRestOfMyProgram); ``` -------------------------------- ### Generate Translated Messages from ARB Source: https://github.com/dart-lang/intl/blob/master/README.md Use the `generate_from_arb.dart` script to create Dart message libraries from translated ARB files. This command takes a prefix for the generated files and the paths to your Dart code and ARB translation files. ```bash > pub run intl_translation:generate_from_arb --generated_file_prefix= ``` -------------------------------- ### Format Date with Default Locale Source: https://github.com/dart-lang/intl/blob/master/README.md Set the default locale and then format the current date using the default DateFormat.jm() pattern. ```dart Intl.defaultLocale = 'es'; DateFormat.jm().format(DateTime.now()); ``` -------------------------------- ### Extract Messages to ARB Source: https://github.com/dart-lang/intl/blob/master/README.md Use the `extract_to_arb.dart` script to extract translatable messages from your Dart source files into an ARB (Application Resource Bundle) file. Specify the output directory and the Dart files to process. ```bash > pub run intl_translation:extract_to_arb --output-dir=target/directory my_program.dart more_of_my_program.dart ``` -------------------------------- ### Format Date with Specific Locale Source: https://github.com/dart-lang/intl/blob/master/README.md Create a DateFormat object for a specific locale to format dates. This allows for locale-specific date representations. ```dart var format = DateFormat.yMd('ar'); var dateString = format.format(DateTime.now()); ``` -------------------------------- ### Define a Plural Message Directly Source: https://github.com/dart-lang/intl/blob/master/README.md Define a plural message directly using Intl.plural, omitting the Intl.message wrapper for top-level plurals. This is a more concise way to handle pluralization. ```dart remainingEmailsMessage(int howMany, String userName) => Intl.plural( howMany, zero: 'There are no emails left for $userName.', one: 'There is $howMany email left for $userName.', other: 'There are $howMany emails left for $userName.', name: 'remainingEmailsMessage', args: [howMany, userName], desc: 'How many emails remain after archiving.', examples: const {'howMany': 42, 'userName': 'Fred'}); ``` -------------------------------- ### Define a Parameterized Message Source: https://github.com/dart-lang/intl/blob/master/README.md Define a message that includes parameters using Dart string interpolation. The 'args' list must match the function parameters. ```dart greetingMessage(name) => Intl.message( 'Hello $name!', name: 'greetingMessage', args: [name], desc: 'Greet the user as they first open the application', examples: const {'name': 'Emily'}); print(greetingMessage('Dan')); ``` -------------------------------- ### Set Default Locale Source: https://github.com/dart-lang/intl/blob/master/README.md Explicitly set the global locale for internationalization operations. ```dart Intl.defaultLocale = 'pt_BR'; ``` -------------------------------- ### Define a Gender Message Source: https://github.com/dart-lang/intl/blob/master/README.md Use Intl.gender to define messages that vary based on the gender of a subject. It supports 'male', 'female', and 'other' cases. ```dart notOnlineMessage(String userName, String userGender) => Intl.gender( userGender, male: '$userName is unavailable because he is not online.', female: '$userName is unavailable because she is not online.', other: '$userName is unavailable because they are not online', name: 'notOnlineMessage', args: [userName, userGender], desc: 'The user is not available to hangout.', examples: const {{'userGender': 'male', 'userName': 'Fred'}, {'userGender': 'female', 'userName' : 'Alice'}}); ``` -------------------------------- ### Access Number Symbols Source: https://github.com/dart-lang/intl/blob/master/README.md Access the symbols object from a NumberFormat instance to retrieve locale-specific formatting information like separators and patterns. ```dart f.symbols ``` -------------------------------- ### Define a Plural Message with Intl.message Source: https://github.com/dart-lang/intl/blob/master/README.md Use Intl.plural within Intl.message to handle pluralization based on a count. This allows for different message variations for zero, one, and other counts. ```dart remainingEmailsMessage(int howMany, String userName) => Intl.message( '''${Intl.plural(howMany, zero: 'There are no emails left for $userName.', one: 'There is $howMany email left for $userName.', other: 'There are $howMany emails left for $userName.')}''', name: 'remainingEmailsMessage', args: [howMany, userName], desc: 'How many emails remain after archiving.', examples: const {'howMany': 42, 'userName': 'Fred'}); print(remainingEmailsMessage(1, 'Fred')); ``` -------------------------------- ### Wrap String with Unicode or HTML Span Source: https://github.com/dart-lang/intl/blob/master/README.md Use BidiFormatter to wrap a string with Unicode directional indicators or an HTML span. The direction can be specified using RTL or LTR constructors, or detected from the text. ```dart BidiFormatter.RTL().wrapWithUnicode('xyz'); BidiFormatter.RTL().wrapWithSpan('xyz'); ``` -------------------------------- ### Perform Operation with Specific Locale Source: https://github.com/dart-lang/intl/blob/master/README.md Execute a block of code using a specific locale, overriding the default locale for the duration of the operation. This is useful for handling different locales within an application. ```dart Intl.withLocale('fr', () => print(myLocalizedMessage())); ``` -------------------------------- ### Pass Locale to Message Function Source: https://github.com/dart-lang/intl/blob/master/README.md Pass a specific locale as an argument to a message formatting function to ensure the message is localized for that locale. ```dart print(myMessage(dateString, locale: 'ar'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.