intl_translation 0.17.10

  • Readme
  • Changelog
  • Installing
  • 89

Intl_translation #

This package provides message extraction and code generation from translated messages for the Intl package. It's a separate package so as to not require a dependency on analyzer for all users.

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.

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. This is an ARB format file which can be used for input to translation tools like Localizely or (the deprecated) 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";

Once the Future returned from the initialization call completes, the message data is available.

0.17.10 #

  • Update petitparser dependency.

0.17.9 #

  • Fix pub complaint trying to precompile a library file in bin by moving that file to lib/src.

0.17.8 #

  • Add --sources-list-files and --translations-list-file to ARB handling utilities to read the input names from files. This is useful for large numbers of inputs.

0.17.7 #

  • Fixed the pubspec to allow intl version 0.16.*

0.17.6 #

  • Strip indentation from generated JSON output to improve codesize.
  • Make generated code not trigger most lints, either by fixing issues or by using lots of ignore_for_file directives.
  • Added --with-source-text option to include the source text in the extracted ARB metadata.

0.17.5 #

  • Allow multiple ARB files with the same locale and combine their translations.
  • Update analyzer constraints and stop using deprecated elements2 API.

0.17.4 #

  • Adds --suppress-meta-data on ARB extraction.
  • Allow Dart enums in an call. The map of cases can either take enums directly, or the short string name of the enum.
  • Handles triple quotes in a translation properly when generating messages as JSON.

0.17.3 #

  • Make require_description also fail for empty strings.
  • Update analyzer dependency.

0.17.2 #

  • Changes to support new mixin syntax.

0.17.1 #

  • Added --suppress-last-modified flag to suppress output of the @@last_modified entry in output file.
  • Add a "package" field in MessageGeneration that can be useful for emitting additional information about e.g. which locales are available and which package we're generating for. Also makes libraryName public.
  • Silence unnecessary_new lint warnings in generated code.
  • Add --require_description command line option to message extraction.

0.17.0 #

  • Fully move to Dart 2.0
  • Delete the transformer and related code.
  • Minor update to analyzer API.
  • Update pubspec version requirements

0.16.8 #

  • Allow message extraction to find messages from prefixed uses of Intl.
  • Move analyzer dependency up to 0.33.0

0.16.7 #

  • Allow message extraction to find messages in class field declarations and top-level declarations.
  • Fix incorrect name and parameters propagation during extraction phase.
  • Still more uppercase constant removal.

0.16.6 #

  • More uppercase constant removal.

0.16.5 #

  • Replace uses of JSON constant for Dart 2 compatibility.

0.16.4 #

  • Update Intl compatibility requirements. This requires at least 0.15.3 of Intl, because the tests contain messages with the new "skip" parameter.

0.16.3 #

0.16.2 #

  • Handle fallback better when we provide translations for locale "xx" but initialize "xx_YY", initializing "xx". Previously we would do nothing.
  • Skip extracting messages that pass the 'skip' argument to Intl calls.
  • Move analyzer dependency up to 0.32.0

0.16.1 #

  • Add @@last_modified to extracted ARB files.
  • Handle @@locale in translated ARB files properly, and adds a --locale parameter to specify the locale.
  • Adds a --output-file parameter to extract_to_arb
  • Indent the output file for ARB for better readability.
  • A couple of tweaks to satisfy Flutter's default linter rules when run on the generated code.

0.16.0 #

  • BREAKING CHANGE: Require that the examples to message/plural/gender/select calls be const. DDC does not optimize non-const maps well, so it's a significant performance issue if these are non-const.
  • Added a utility to convert examples in calls to be const. See bin/make_examples_const.dart
  • Add a codegen_mode flag, which can be either release or debug. In release mode a missing translation throws an exception, in debug mode it returns the original text, which was the previous behavior.
  • Add support for generating translated messages as JSON rather than methods. This can significantly improve dart2js compile times for applications with many translations. The JSON is a literal string in the deferred library, so usage doesn't change at all.

0.15.0 #

  • Change non-transformer message rewriting to preserve the original message as much as possible. Adds --useStringSubstitution command-line arg.
  • Change non-transformer message rewriting to allow multiple input files to be specified on the command line. Adds --replace flag to ignore --output option and just replace files.
  • Make non-transformer message rewriting also run dartfmt on the output.
  • Make message extraction more robust: error message instead of stack trace when an Intl call is made outside a method, when a prefixed expression is used in an interpolation, and when a non-required example Map is not a literal.
  • Make message extraction more robust: if parsing triggers an exception then report it as an error instead of exiting.
  • Move barback to being a normal rather than a dev dependency.
  • Add a check for invalid select keywords.
  • Added a post-message construction validate, moved IntlMessageExtractionException into intl_message.dart
  • Make use of analyzer's new AstFactory class (requires analyzer version 0.29.1).
  • Fix error in transformer, pass the path instead of the asset id.
  • Prefer an explicit =0/=1/=2 to a ZERO/ONE/TWO if both are present. We don't distinguish the two as Intl.message arguments, we just have the "one" parameter, which we confusingly write out as =1. Tools interpret these differently, and in particular, a ONE clause is used for the zero case if there's no explicit zero. Translation tools may implement this by filling in both ZERO and ONE values with the OTHER clause when there's no ZERO provided, resulting in a translation with both =1 and ONE clauses which are different. We should prefer the explicit =1 in that case. In future we may distinguish the different forms, but that would probably break existing translations.
  • Switch to using package:test
  • Give a more specific type in the generated code to keep lints happy.

0.14.0 #

  • Split message extraction and code generation out into a separate package. Versioned to match the corresponding Intl version.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  intl_translation: ^0.17.10

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:intl_translation/extract_messages.dart';
import 'package:intl_translation/generate_localized.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/intl_message.dart. (-14.39 points)

Analysis of lib/src/intl_message.dart reported 31 hints, including:

line 35 col 1: 'package:analyzer/analyzer.dart' is deprecated and shouldn't be used.

line 40 col 21: Avoid const keyword.

line 67 col 29: Unnecessary new keyword.

line 102 col 14: Unnecessary new keyword.

line 133 col 33: Use = to separate a named parameter from its default value.

Fix lib/extract_messages.dart. (-12.66 points)

Analysis of lib/extract_messages.dart reported 27 hints, including:

line 24 col 1: 'package:analyzer/analyzer.dart' is deprecated and shouldn't be used.

line 91 col 19: Unnecessary new keyword.

line 100 col 16: 'parseCompilationUnit' is deprecated and shouldn't be used. Please use parseString instead.

line 119 col 18: Unnecessary new keyword.

line 142 col 45: Unnecessary new keyword.

Fix bin/generate_from_arb.dart. (-6.78 points)

Analysis of bin/generate_from_arb.dart reported 14 hints, including:

line 37 col 21: Avoid const keyword.

line 41 col 16: Unnecessary new keyword.

line 42 col 20: Unnecessary new keyword.

line 43 col 20: Unnecessary new keyword.

line 49 col 19: Unnecessary new keyword.

Fix additional 5 files with analysis or formatting issues. (-14.77 points)

Additional issues in the following files:

  • bin/extract_to_arb.dart (9 hints)
  • lib/src/message_rewriter.dart (8 hints)
  • bin/make_examples_const.dart (7 hints)
  • bin/rewrite_intl_messages.dart (5 hints)
  • lib/generate_localized.dart (1 hint)

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and intl_translation.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
analyzer >=0.36.0 <0.40.0 0.39.6
args >=0.12.1 <2.0.0 1.6.0
dart_style ^1.0.0 1.3.4
intl >=0.15.3 <0.17.0 0.16.1
path >=0.9.0 <2.0.0 1.6.4
petitparser ^3.0.0 3.0.2
Transitive dependencies
_fe_analyzer_shared 2.1.0
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.9.3
pedantic 1.9.0
pub_semver 1.4.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+14
yaml 2.2.0
Dev dependencies
test ^1.2.0