{"id":13395619,"url":"https://github.com/dart-archive/intl","last_synced_at":"2025-10-23T01:17:49.490Z","repository":{"id":24163714,"uuid":"27553868","full_name":"dart-archive/intl","owner":"dart-archive","description":"Internationalization and localization support","archived":true,"fork":false,"pushed_at":"2023-04-19T14:21:06.000Z","size":1920,"stargazers_count":528,"open_issues_count":1,"forks_count":168,"subscribers_count":54,"default_branch":"master","last_synced_at":"2024-04-10T02:08:36.291Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/intl","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dart-archive.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2014-12-04T18:26:32.000Z","updated_at":"2024-04-07T05:28:28.000Z","dependencies_parsed_at":"2023-11-13T13:31:06.177Z","dependency_job_id":"8eb28f90-72a9-4082-ba96-6fda0fa628b5","html_url":"https://github.com/dart-archive/intl","commit_stats":null,"previous_names":["dart-lang/intl"],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dart-archive%2Fintl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dart-archive%2Fintl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dart-archive%2Fintl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dart-archive%2Fintl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dart-archive","download_url":"https://codeload.github.com/dart-archive/intl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221303554,"owners_count":16794777,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:00:26.555Z","updated_at":"2025-10-23T01:17:49.035Z","avatar_url":"https://github.com/dart-archive.png","language":"Dart","funding_links":[],"categories":["Development-Tools","Dart"],"sub_categories":[],"readme":"## This repository has been moved to https://github.com/dart-lang/i18n/tree/main/pkgs/intl. Please file any PRs and issues there.\n---\n\n[![Dart CI](https://github.com/dart-lang/intl/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/intl/actions/workflows/test-package.yml)\n[![Pub](https://img.shields.io/pub/v/intl.svg)](https://pub.dev/packages/intl)\n\nProvides internationalization and localization facilities,\nincluding message translation, plurals and genders, date/number formatting\nand parsing, and bidirectional text.\n\n## General\nThe most important library is [intl][intl_lib]. It defines the [Intl][Intl]\nclass, with the default locale and methods for accessing most of the\ninternationalization mechanisms. This library also defines the\n[DateFormat][DateFormat], [NumberFormat][NumberFormat], and\n[BidiFormatter][BidiFormatter] classes.\n\n## Current locale\n\nThe package has a single current locale, called [defaultLocale][defaultLocale].\nOperations will use that locale unless told to do otherwise.\n\nYou can explicitly set the global locale\n\n```dart\nIntl.defaultLocale = 'pt_BR';\n```\n\nor get it from the browser\n\n```dart\nimport 'package:intl/intl_browser.dart';\n...\nfindSystemLocale().then(runTheRestOfMyProgram);\n```\n\nTo override the current locale for a particular operation, pass the operation\nto [withLocale][withLocale]. Note that this includes async tasks\nspawned from that operation, and that the argument to\n[withLocale][withLocale]\nwill supercede the [defaultLocale][defaultLocale] while the operation\nis active. If you are using different locales within an application,\nthe [withLocale][withLocale] operation may be preferable to setting\n[defaultLocale][defaultLocale].\n\n```dart\nIntl.withLocale('fr', () =\u003e print(myLocalizedMessage()));\n```\n\nTo specify the locale for an operation you can create a format object in\na specific locale, pass in the locale as a parameter to methods, or\nset the default locale.\n\n```dart\nvar format = DateFormat.yMd('ar');\nvar dateString = format.format(DateTime.now());\n```\n\nor\n\n```dart\nprint(myMessage(dateString, locale: 'ar');\n```\n\nor\n\n```dart\nIntl.defaultLocale = 'es';\nDateFormat.jm().format(DateTime.now());\n```\n\n## Initialization\n\nAll the different types of locale data require an async initialization step\nto make\nsure the data is available. This reduces the size of the application by only\nloading the\ndata that is actually required.\n\nEach different area of internationalization (messages, dates, numbers) requires\na separate initialization process. That way, if the application only needs to\nformat dates, it doesn't need to take the time or space to load up messages,\nnumbers, or other things it may not need.\n\nWith messages, there is also a need to import a file that won't exist until\nthe code generation step has been run. This can be awkward, but can be worked\naround by creating a stub `messages_all.dart` file, running an empty translation\nstep, or commenting out the import until translations are available.\nSee \"Extracting and Using Translated Messages\"\n\n## Messages\n\nMessages to be localized are written as functions that return the result of\nan [Intl.message][Intl.message] call.\n\n```dart\nString continueMessage() =\u003e Intl.message(\n    'Hit any key to continue',\n    name: 'continueMessage',\n    args: [],\n    desc: 'Explains that we will not proceed further until '\n        'the user presses a key');\nprint(continueMessage());\n```\n\nThis provides, in addition to the basic message string, a name, a description\nfor translators, the arguments used in the message, and examples. The `name` and\n`args` parameters must match the name (or ClassName_methodName) and arguments\nlist of the function respectively. For messages without parameters, both of\nthese can be omitted.\n\nA function with an Intl.message call can be run in the program before any\ntranslation has been done, and will just return the message string. It can also\nbe extracted to a file and then be made to return a translated version without\nmodifying the original program. See \"Extracting Messages\" below for more\ndetails.\n\nThe purpose of wrapping the message in a function is to allow it to\nhave parameters which can be used in the result. The message string is\nallowed to use a restricted form of Dart string interpolation, where\nonly the function's parameters can be used, and only in simple\nexpressions. Local variables cannot be used, and neither can\nexpressions with curly braces. Only the message string can have\ninterpolation. The name, desc, args, and examples must be literals and\nnot contain interpolations. Only the args parameter can refer to\nvariables, and it should list exactly the function parameters. If you\nare passing numbers or dates and you want them formatted, you must do\nthe formatting outside the function and pass the formatted string into\nthe message.\n\n```dart\ngreetingMessage(name) =\u003e Intl.message(\n    'Hello $name!',\n    name: 'greetingMessage',\n    args: [name],\n    desc: 'Greet the user as they first open the application',\n    examples: const {'name': 'Emily'});\nprint(greetingMessage('Dan'));\n```\n\nThere is one special class of complex expressions allowed in the\nmessage string, for plurals and genders.\n\n```dart\nremainingEmailsMessage(int howMany, String userName) =\u003e\n  Intl.message(\n    '''${Intl.plural(howMany,\n        zero: 'There are no emails left for $userName.',\n        one: 'There is $howMany email left for $userName.',\n        other: 'There are $howMany emails left for $userName.')}''',\n  name: 'remainingEmailsMessage',\n  args: [howMany, userName],\n  desc: 'How many emails remain after archiving.',\n  examples: const {'howMany': 42, 'userName': 'Fred'});\n\nprint(remainingEmailsMessage(1, 'Fred'));\n```\n\nHowever, since the typical usage for a plural or gender is for it to\nbe at the top-level, we can also omit the [Intl.message][Intl.message] call and\nprovide its parameters to the [Intl.plural][Intl.plural] call instead.\n\n```dart\nremainingEmailsMessage(int howMany, String userName) =\u003e\n  Intl.plural(\n    howMany,\n    zero: 'There are no emails left for $userName.',\n    one: 'There is $howMany email left for $userName.',\n    other: 'There are $howMany emails left for $userName.',\n    name: 'remainingEmailsMessage',\n    args: [howMany, userName],\n    desc: 'How many emails remain after archiving.',\n    examples: const {'howMany': 42, 'userName': 'Fred'});\n```\n\nSimilarly, there is an [Intl.gender][Intl.gender] message, and plurals\nand genders can be nested.\n\n```dart\nnotOnlineMessage(String userName, String userGender) =\u003e\n  Intl.gender(\n    userGender,\n    male: '$userName is unavailable because he is not online.',\n    female: '$userName is unavailable because she is not online.',\n    other: '$userName is unavailable because they are not online',\n    name: 'notOnlineMessage',\n    args: [userName, userGender],\n    desc: 'The user is not available to hangout.',\n    examples: const {{'userGender': 'male', 'userName': 'Fred'},\n        {'userGender': 'female', 'userName' : 'Alice'}});\n```\n\nIt's recommended to use complete sentences in the sub-messages to keep\nthe structure as simple as possible for the translators.\n\n## Extracting And Using Translated Messages\n\nWhen your program contains messages that need translation, these must\nbe extracted from the program source, sent to human translators, and the\nresults need to be incorporated. The code for this is in the\n[Intl_translation][Intl_translation] package.\n\nTo extract messages, run the `extract_to_arb.dart` program.\n\n```console\n\u003e pub run intl_translation:extract_to_arb --output-dir=target/directory\n    my_program.dart more_of_my_program.dart\n```\n\nThis will produce a file `intl_messages.arb` with the messages from\nall of these programs. See [ARB][ARB].\nThe resulting translations can be used to generate a set of libraries\nusing the `generate_from_arb.dart` program.\n\nThis expects to receive a series of files, one per\nlocale.\n\n```console\n\u003e pub run intl_translation:generate_from_arb --generated_file_prefix=\u003cprefix\u003e\n    \u003cmy_dart_files\u003e \u003ctranslated_ARB_files\u003e\n```\n\nThis will generate Dart libraries, one per locale, which contain the\ntranslated versions. Your Dart libraries can import the primary file,\nnamed `\u003cprefix\u003emessages_all.dart`, and then call the initialization\nfor a specific locale. Once that's done, any\n[Intl.message][Intl.message] calls made in the context of that locale\nwill automatically print the translated version instead of the\noriginal.\n\n```dart\nimport 'my_prefix_messages_all.dart';\n...\ninitializeMessages('dk').then(printSomeMessages);\n```\n\nOnce the future returned from the initialization call returns, the\nmessage data is available.\n\n## Number Formatting and Parsing\n\nTo format a number, create a NumberFormat instance.\n\n```dart\nvar f = NumberFormat('###.0#', 'en_US');\nprint(f.format(12.345));\n  ==\u003e 12.35\n```\n\nThe locale parameter is optional. If omitted, then it will use the\ncurrent locale. The format string is as described in\n[NumberFormat][NumberFormat]\n\nIt's also possible to access the number symbol data for the current\nlocale, which provides information as to the various separator\ncharacters, patterns, and other information used for formatting, as\n\n```dart\nf.symbols\n```\n\nCurrent known limitations are that the currency format will only print\nthe name of the currency, and does not support currency symbols, and\nthat the scientific format does not really agree with scientific\nnotation. Number parsing is not yet implemented.\n\n## Date Formatting and Parsing\n\nTo format a [DateTime][DateTime], create a [DateFormat][DateFormat]\ninstance. These can be created using a set of commonly used skeletons\ntaken from ICU/CLDR or using an explicit pattern. For details on the\nsupported skeletons and patterns see [DateFormat][DateFormat].\n\n```dart\nDateFormat.yMMMMEEEEd().format(aDateTime);\n  ==\u003e 'Wednesday, January 10, 2012'\nDateFormat('EEEEE', 'en_US').format(aDateTime);\n  ==\u003e 'Wednesday'\nDateFormat('EEEEE', 'ln').format(aDateTime);\n  ==\u003e 'mokɔlɔ mwa mísáto'\n```\n\nYou can also parse dates using the same skeletons or patterns.\n\n```dart\nDateFormat.yMd('en_US').parse('1/10/2012');\nDateFormat('Hms', 'en_US').parse('14:23:01');\n```\n\nSkeletons can be combined, the main use being to print a full date and\ntime, e.g.\n\n```dart\nDateFormat.yMEd().add_jms().format(DateTime.now());\n  ==\u003e 'Thu, 5/23/2013 10:21:47 AM'\n```\n\nKnown limitations: Time zones are not yet supported. Dart\n[DateTime][DateTime] objects don't have a time zone, so are either\nlocal or UTC. Formatting and parsing Durations is not yet implemented.\n\nNote that before doing any DateTime formatting for a particular\nlocale, you must load the appropriate data by calling.\n\n```dart\nimport 'package:intl/date_symbol_data_local.dart';\n...\ninitializeDateFormatting('de_DE', null).then(formatDates);\n```\n\nOnce the future returned from the initialization call returns, the\nformatting data is available.\n\nThere are other mechanisms for loading the date formatting data\nimplemented, but we expect to deprecate those in favor of having the\ndata in a library as in the above, and using deferred loading to only\nload the portions that are needed. For the time being, this will\ninclude all of the data, which will increase code size.\n\n## Bidirectional Text\n\nThe class [BidiFormatter][BidiFormatter] provides utilities for\nworking with Bidirectional text. We can wrap the string with unicode\ndirectional indicator characters or with an HTML span to indicate\ndirection. The direction can be specified with the\n[RTL][BidiFormatter.RTL] and [LTR][BidiFormatter.LTR] constructors, or\ndetected from the text.\n\n```dart\nBidiFormatter.RTL().wrapWithUnicode('xyz');\nBidiFormatter.RTL().wrapWithSpan('xyz');\n```\n\n[intl_lib]: https://pub.dev/documentation/intl/latest/intl/intl-library.html\n[Intl]: https://pub.dev/documentation/intl/latest/intl/Intl-class.html\n[DateFormat]: https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html\n[NumberFormat]: https://pub.dev/documentation/intl/latest/intl/NumberFormat-class.html\n[withLocale]: https://pub.dev/documentation/intl/latest/intl/Intl/withLocale.html\n[defaultLocale]: https://pub.dev/documentation/intl/latest/intl/Intl/defaultLocale.html\n[Intl.message]: https://pub.dev/documentation/intl/latest/intl/Intl/message.html\n[Intl_translation]: https://pub.dev/packages/intl_translation\n[Intl.plural]: https://pub.dev/documentation/intl/latest/intl/Intl/plural.html\n[Intl.gender]: https://pub.dev/documentation/intl/latest/intl/Intl/gender.html\n[DateTime]: https://api.dart.dev/dart-core/DateTime-class.html\n[BidiFormatter]: https://pub.dev/documentation/intl/latest/intl/BidiFormatter-class.html\n[BidiFormatter.RTL]: https://pub.dev/documentation/intl/latest/intl/BidiFormatter/BidiFormatter.RTL.html\n[BidiFormatter.LTR]: https://pub.dev/documentation/intl/latest/intl/BidiFormatter/BidiFormatter.LTR.html\n[ARB]: https://github.com/google/app-resource-bundle\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdart-archive%2Fintl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdart-archive%2Fintl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdart-archive%2Fintl/lists"}