Druxtan
Druxtan

Reputation: 1329

Dart i18n library

I'm trying to use the package intl but my brain fails to understand ...

Do you have a simple example of how to use it, when we come from chrome.i18n?

Upvotes: 2

Views: 832

Answers (2)

Alan Knight
Alan Knight

Reputation: 2971

Here's a sample - https://github.com/dart-lang/sample-polymer-intl

Top-level explanation: You write your message initially wrapped in an Intl.message call, which should be in a function that does just that. So, e.g.

  hello() => Intl.message("Hello world");
  print(hello());

If you run that it will just run without any modification. You can extract out the messages using bin/extract_to_arb.dart, translate them, and run bin/generate_from_arb.dart.

Compared to chrome.i18n:

  • You write your message in this wrapped-in-a-function-style and the default locale (let's say English) version just runs.
  • Your program doesn't read the JSON files directly, you run a code generator on them and it generates a library per locale.
  • You don't use getMessage or anything, it just runs the same way it did before.
  • To use messages from a particular locale you initialize the locale (which loads the deferred library) and then set it as the default.
  • It generates and consumes ARB files, and the interpretation of messages is like ICU.

Is that what you were looking for?

Upvotes: 1

Suguru Inatomi
Suguru Inatomi

Reputation: 47

If you just want to localize some messages, I think that l10n would be nice to you. It generates PO files and use it to translate.

Upvotes: 1

Related Questions