Update //third_party/dart_lang/trunk, v2 and macos_sdk to 30719b37a9397cc38610e71a804236ec314535ec.

This CL also updates //third_party/dart/tflite_native and
//third_party/dart/intl to fresh ffi API and imports package:ffi to
//third_party/dart/ffi

New changes in trunk:

  - 30719b37a9397cc38610e71a804236ec314535ec [analyzer/ffi] Allow "Pointer<NativeType>" in native func... by Martin Kustermann <kustermann@google.com>
  - 9f1b0fe102c0ad4599b695974621530f07684290 [cfe] Handle explicit extension operator calls by Johnni Winther <johnniwinther@google.com>
  - 9e636b5ab4de850fb19bc262e0686fdf14bfbfc0 Reland "[vm/service] Introduce IsolateGroup entity to vm ... by Alexander Aprelev <aam@google.com>
  - 8e7fa2a35b32eab34e6a3fb86a13dbba7bda5812 NNBD i13n: Proper messages for nullable values in collect... by Sam Rawlins <srawlins@google.com>
  - c52ac7b1144157a7bc975c30d473321da82fe04e Migration: ensure that the target of cascade expressions ... by Paul Berry <paulberry@google.com>
  - 1b044eec083f8332983194704396ceafccad8ed1 Combine nullabilities during substitution. by Konstantin Shcheglov <scheglov@google.com>
  - c2489c2f5326000883688d7dbc5290f98f8b10e0 Issue 38811. Fix for reporting MISSING_DEFAULT_VALUE_FOR_... by Konstantin Shcheglov <scheglov@google.com>
  - 0b045aea2b0dc40f4770c63dec2ebb99fed06331 [ VM ] Removed tests/standalone along with any references... by Ben Konyi <bkonyi@google.com>
  - 6d029cac3b53e70e812ffe9f0dec330352ee11ee [vm] Fixing warnings in newer Clang versions. by Ryan Macnak <rmacnak@google.com>
  - a9d0987476c111288a51ca4fd67890d5df344419 Migration: generalize FixBuilder's representation of chan... by Paul Berry <paulberry@google.com>
  - 9fe78bc9a816426737827a5b404ff42fbe65dfac Support for 'question' in FieldFormalParameter. by Konstantin Shcheglov <scheglov@google.com>
  - 1e3e9ee04c58b38b845c069227b1d308f5b03cd0 Flow analysis: introduce a debug implementation. by Paul Berry <paulberry@google.com>
  - 68d398b392fee6a96a9bd4352d93b361c599a2d8 [analyzer] add more diagnostics for ML completion by Devon Carew <devoncarew@google.com>
  - 3e992eb8fe10abc709da56f6e29af20f3b19dfda NNBD i13n: Add line numbers to a few messages by Sam Rawlins <srawlins@google.com>
  - 558875d4809d41dda5892beeeabf3e057a5d056e [ VM / dart:io ] Added service extension scaffolding for ... by Ben Konyi <bkonyi@google.com>
  - dfa50ae87be975d4c74b334a86fd2847c9a3c790 [vm,bytecode] Drop AST by default when generating bytecod... by Alexander Markov <alexmarkov@google.com>
  - 8f1913ff1b57d3edb24cbfefb3afbe1fed84fde2 [dart2js] New RTI: Clean up "any" hack in recipe encoder. by Mayank Patke <fishythefish@google.com>
  - 0649cb7755f3dd4eae3c5a22375bc159018450c5 Issue 38900. Fix type parameter type NonNull promotion. by Konstantin Shcheglov <scheglov@google.com>
  - 41bc899b5657a18b065d4472303a8807e42b8d05 Check for implicit cast using computeVariance(). by Konstantin Shcheglov <scheglov@google.com>
  - 3964afdbc59f85982518b973b22e7c0430755c8f [dart2js] New RTI: Stop recognizing "dynamic" as a recipe. by Mayank Patke <fishythefish@google.com>
  - c19adc635542004d2c2cdac55b447e7175391bf8 [vm,aot] Fix handling of exported extensions in TFA tree ... by Alexander Markov <alexmarkov@google.com>
  - 630100fb16af150e8620287d975734e8a8b653dc Don't allow ML to suggest punctuation by reference by Ari Aye <ariaye@google.com>
  - f020ce5d23a50c05b10c372d99a3f7a878420c78 Revert "[vm/service] Introduce IsolateGroup entity to vm ... by Alexander Aprelev <aam@google.com>
  - c4a7f1c6bfb8735e392d105ba29eca9dab00d394 Revert "[vm/compiler] Mark more stores as initializing." by Ben Konyi <bkonyi@google.com>
  - 01bd0ab62f4cfc5cfaba722d1bf49b33f17027d0 [vm/fuzzer] Always add OOM catch in try-catch-finally by Aart Bik <ajcbik@google.com>
  - 2cee751fb97c5af1406bd76c71582c62f9bbeea7 dartfix: Don't sort edits when using --outputDir; fixes #... by Sam Rawlins <srawlins@google.com>
  - 7b135fc7a6cdc4567d6d857b73b8953a3e6c3c5c Differentiate between legacy and sound covariance. by Kallen Tu <kallentu@google.com>
  - f219e5152d4e447a5a8b09f6bf0fb0dcd263877e [vm/service] Introduce IsolateGroup entity to vm service ... by Alexander Aprelev <aam@google.com>
  - 2c94e561587bba2ee01bbf4deee46b1aac6334b1 [vm] Implementation of the null check instruction in the ... by Liam Appelbe <liama@google.com>
  - c0a46e7b5a0ce346546286c77e3e9a3e80cf55e5 [vm/compiler] improve redundant store elimination by Aart Bik <ajcbik@google.com>
  - f26aa6fff4deb53f8dddacdc1125fb685eea4a93 [vm, bytecode] Put the 'main' sub-component last when gen... by Ryan Macnak <rmacnak@google.com>
  - 88e7fbbe68b7679a9c0133410a37ef2b9c56e742 [ dart:developer ] Update documentation for TimelineTask.... by Ben Konyi <bkonyi@google.com>
  - 17a5460b4921a4a9c6d8b57cd3ddd45b57ef53e8 [vm] Add --no-bytecode gn option by Alexander Markov <alexmarkov@google.com>
  - e47ab49f0c4f09b94ce2889d3931441354ad2cb8 [analyzer] add a diagnostics page for ml completion by Devon Carew <devoncarew@google.com>
  - eb87e79e8e0c14c6837e028209450d76835f137f [vm/compiler] Mark more stores as initializing. by Vyacheslav Egorov <vegorov@google.com>
  - dee702264b4ab6f6b634b2e346de5ac7ea08b042 [cfe] Handle named arguments on extensions methods correc... by Johnni Winther <johnniwinther@google.com>
  - 504c45fe2b0bc62dfba454d87682428eaa5eead3 [CFE] Don't cleanup moved parts in uriToSource by Jens Johansen <jensj@google.com>
  - f3294f708361d1226e99df4de1d997434d923cb1 [cfe] Ignore context when de-duplicating error messages by Aske Simon Christensen <askesc@google.com>
  - ed1e0e199eceb4ce0b0530acdb231f0c3bc989bc [vm/ffi] Handle IntConverter's similar to LoadUntagged in... by Martin Kustermann <kustermann@google.com>
  - 23e8f2bcfa045471e4ed7c7834c04760f2fc6b43 [cfe] Verify that Null is always nullable by Dmitry Stefantsov <dmitryas@google.com>
  - 9634e053cb51629c67032cd9a0976b4db050c7e4 [analyzer/ffi] Remove Struct type parameter in analyzer m... by Martin Kustermann <kustermann@google.com>
  - f95a1abbeec80ab939dea8d879ae0711184f5c64 [CFE] Recognize >>> in Symbol when triple-shift flag is e... by Aske Simon Christensen <askesc@google.com>
  - e00048285267f742438934d15060e25c6c9b5d6c [cfe] Better marker length when pointing to a constructor by Aske Simon Christensen <askesc@google.com>
  - dd140495e7c76de8853edf1837cc786ef23b9e57 [cfe] Position on != by Aske Simon Christensen <askesc@google.com>
  - ca669032c39bc7d5a3d2ef611e012c757db6459f [vm/aot] Re-enable dwarf_stack_trace_test. by Samir Jindel <sjindel@google.com>
  - 2ed7b63abd797dcbdf73596bfa7668b57d259ae4 [cfe] Describe subtype relation in "Nullability in CFE" by Dmitry Stefantsov <dmitryas@google.com>
  - dbf63583ff10b8557153bfe664df53e9d3a4acbf [cfe] Add .withNullability to the "Nullability in CFE" doc by Dmitry Stefantsov <dmitryas@google.com>
  - c9f6e669f90eacdb2d5c982beffb33b5a0fbf789 [vm/compiler] Reland "Further compress the information...... by Teagan Strickland <sstrickl@google.com>
  - bdf02028cd582c3380b616978efe5da564bba8b9 [vm/ffi] Remove deprecated methods by Daco Harkes <dacoharkes@google.com>
  - f1657ab934d212be3f37bc0626c4a0a6764694b5 NNBD i13n: Handle returned values in deeper expressions by Sam Rawlins <srawlins@google.com>
  - cf9c6134b870fd272803b20e7e1ee89d2bb26abc Move consumerName(Request) from the analysis server gener... by Jaime Wren <jwren@google.com>
  - fbc406aec3955440bc12e8a1dcb7164d2a996abe Revert "[vm,aot] Simple unreachable code elimination befo... by Alexander Markov <alexmarkov@google.com>
  - 2e6695f6f94c9cf01b666c464d28ec69b4cf5ed6 NNBD i13n: Add line numbers by Sam Rawlins <srawlins@google.com>
  - e221f83febb696841d43d5668f9c799c70210981 Set nullability for function typed formal parameters. by Konstantin Shcheglov <scheglov@google.com>
  - a73eba98235494b48497c59bba32167a315af5de [dartdevc] Preliminary additions to support NNBD runtime ... by Nicholas Shahan <nshahan@google.com>
  - 41b65b27c20ee76cfafe73384d3b6b2e46ec3667 [vm,aot] Simple unreachable code elimination before type-... by Alexander Markov <alexmarkov@google.com>
  - 81679a2ab45ac359fb2ef119d1349dbb99c9574e [analyzer] reduce the default number of times we repeat a... by Devon Carew <devoncarew@google.com>
  - 2e237765525b1673a42669760a1135dac7223417 [dartdevc] Add new bot configuration for nnbd strong by Nicholas Shahan <nshahan@google.com>
  - cfe25c7e95790f5a9dfdc6934a712428b731507b NNBD i13n: Sort navigation links by Sam Rawlins <srawlins@google.com>
  - e642af52a5e1c52f2f4c03bfc7355e28e26458fb Fix behavior of ML query construction by Ari Aye <ariaye@google.com>
  - 65bf2f0bcdab83e301e7748e9affb9c509b70000 [VM] Fix name demangling in AOT mode. by asiva <asiva@google.com>
  - 95bd6a288857e8c14727cecb14c6c295d558e605 Fix --completion-model flag by Ari Aye <ariaye@google.com>

PiperOrigin-RevId: 275245017
1 file changed
tree: f6149324dcdc50d13d446781cbbbc85be406531e
  1. lib/
  2. test/
  3. tool/
  4. .gitignore
  5. .status
  6. .travis.yml
  7. AUTHORS
  8. CHANGELOG.md
  9. codereview.settings
  10. dart_test.yaml
  11. LICENSE
  12. PATENTS
  13. pubspec.yaml
  14. README.md
README.md

Intl

This package provides internationalization and localization facilities, including message translation, plurals and genders, date/number formatting and parsing, and bidirectional text.

General

The most important library is intl. It defines the Intl class, with the default locale and methods for accessing most of the internationalization mechanisms. This library also defines the DateFormat, NumberFormat, and BidiFormatter classes.

Current locale

The package has a single current locale, called defaultLocale. Operations will use that locale unless told to do otherwise.

You can explicitly set the global locale

  Intl.defaultLocale = 'pt_BR';

or get it from the browser

  import 'package:intl/intl_browser.dart';
  ...
  findSystemLocale().then(runTheRestOfMyProgram);

To override the current locale for a particular operation, pass the operation to withLocale. Note that this includes async tasks spawned from that operation, and that the argument to withLocale will supercede the defaultLocale while the operation is active. If you are using different locales within an application, the withLocale operation may be preferable to setting defaultLocale.

  Intl.withLocale('fr', () => print(myLocalizedMessage());

To specify the locale for an operation you can create a format object in a specific locale, pass in the locale as a parameter to methods, or set the default locale.

var format = DateFormat.yMd('ar');
var dateString = format.format(DateTime.now());

or

print(myMessage(dateString, locale: 'ar');

or

Intl.defaultLocale = 'es';
DateFormat.jm().format(DateTime.now());

Initialization

All the different types of locale data require an async initialization step to make sure the data is available. This reduces the size of the application by only loading the data that is actually required.

Each different area of internationalization (messages, dates, numbers) requires a separate initialization process. That way, if the application only needs to format dates, it doesn't need to take the time or space to load up messages, numbers, or other things it may not need.

With messages, there is also a need to import a file that won't exist until the code generation step has been run. This can be awkward, but can be worked around by creating a stub messages_all.dart file, running an empty translation step, or commenting out the import until translations are available. See “Extracting and Using Translated Messages”

Messages

Messages to be localized are written as functions that return the result of an Intl.message call.

  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());

This provides, in addition to the basic message string, a name, a description for translators, the arguments used in the message, and examples. The name and args parameters must match the name (or ClassName_methodName) and arguments list of the function respectively. For messages without parameters, both of these can be omitted.

A function with an Intl.message call can be run in the program before any translation has been done, and will just return the message string. It can also be extracted to a file and then be made to return a translated version without modifying the original program. See “Extracting Messages” below for more details.

The purpose of wrapping the message in a function is to allow it to have parameters which can be used in the result. The message string is allowed to use a restricted form of Dart string interpolation, where only the function's parameters can be used, and only in simple expressions. Local variables cannot be used, and neither can expressions with curly braces. Only the message string can have interpolation. The name, desc, args, and examples must be literals and not contain interpolations. Only the args parameter can refer to variables, and it should list exactly the function parameters. If you are passing numbers or dates and you want them formatted, you must do the formatting outside the function and pass the formatted string into the message.

  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'));

There is one special class of complex expressions allowed in the message string, for plurals and genders.

  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'));

However, since the typical usage for a plural or gender is for it to be at the top-level, we can also omit the Intl.message call and provide its parameters to the Intl.plural call instead.

  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'});

Similarly, there is an Intl.gender message, and plurals and genders can be nested.

  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'}});

It's recommended to use complete sentences in the sub-messages to keep the structure as simple as possible for the translators.

Extracting And Using Translated Messages

When your program contains messages that need translation, these must be extracted from the program source, sent to human translators, and the results need to be incorporated. The code for this is in the Intl_translation package.

To extract messages, run the extract_to_arb.dart program.

  pub run intl_translation:extract_to_arb --output-dir=target/directory
      my_program.dart more_of_my_program.dart

This will produce a file intl_messages.arb with the messages from all of these programs. an ARB format file which can be used for input to translation tools like Google Translator Toolkit. The resulting translations can be used to generate a set of libraries using the generate_from_arb.dart program.

This expects to receive a series of files, one per locale.

pub run intl_translation:generate_from_arb --generated_file_prefix=<prefix>
    <my_dart_files> <translated_ARB_files>

This will generate Dart libraries, one per locale, which contain the translated versions. Your Dart libraries can import the primary file, named <prefix>messages_all.dart, and then call the initialization for a specific locale. Once that's done, any Intl.message calls made in the context of that locale will automatically print the translated version instead of the original.

  import 'my_prefix_messages_all.dart';
  ...
  initializeMessages('dk').then(printSomeMessages);

Once the future returned from the initialization call returns, the message data is available.

Number Formatting and Parsing

To format a number, create a NumberFormat instance.

  var f = NumberFormat('###.0#', 'en_US');
  print(f.format(12.345));
    ==> 12.34

The locale parameter is optional. If omitted, then it will use the current locale. The format string is as described in NumberFormat

It's also possible to access the number symbol data for the current locale, which provides information as to the various separator characters, patterns, and other information used for formatting, as

  f.symbols

Current known limitations are that the currency format will only print the name of the currency, and does not support currency symbols, and that the scientific format does not really agree with scientific notation. Number parsing is not yet implemented.

Date Formatting and Parsing

To format a DateTime, create a DateFormat instance. These can be created using a set of commonly used skeletons taken from ICU/CLDR or using an explicit pattern. For details on the supported skeletons and patterns see DateFormat.

  DateFormat.yMMMMEEEEd().format(aDateTime);
    ==> 'Wednesday, January 10, 2012'
  DateFormat('EEEEE', 'en_US').format(aDateTime);
    ==> 'Wednesday'
  DateFormat('EEEEE', 'ln').format(aDateTime);
    ==> 'mokɔlɔ mwa mísáto'

You can also parse dates using the same skeletons or patterns.

    DateFormat.yMd('en_US').parse('1/10/2012');
    DateFormat('Hms', 'en_US').parse('14:23:01');

Skeletons can be combined, the main use being to print a full date and time, e.g.

    DateFormat.yMEd().add_jms().format(DateTime.now());
      ==> 'Thu, 5/23/2013 10:21:47 AM'

Known limitations: Time zones are not yet supported. Dart DateTime objects don't have a time zone, so are either local or UTC. Formatting and parsing Durations is not yet implemented.

Note that before doing any DateTime formatting for a particular locale, you must load the appropriate data by calling.

    import 'package:intl/date_symbol_data_local.dart';
    ...
    initializeDateFormatting('de_DE', null).then(formatDates);

Once the future returned from the initialization call returns, the formatting data is available.

There are other mechanisms for loading the date formatting data implemented, but we expect to deprecate those in favor of having the data in a library as in the above, and using deferred loading to only load the portions that are needed. For the time being, this will include all of the data, which will increase code size.

Bidirectional Text

The class BidiFormatter provides utilities for working with Bidirectional text. We can wrap the string with unicode directional indicator characters or with an HTML span to indicate direction. The direction can be specified with the RTL and LTR constructors, or detected from the text.

    BidiFormatter.RTL().wrapWithUnicode('xyz');
    BidiFormatter.RTL().wrapWithSpan('xyz');