intl_messages 1.1.3

  • Readme
  • Changelog
  • Installing
  • 66

intl_messages #

A Simple and easy library for Message Internationalization and Localization (I18N).

Main features: #

  • Structure of messages by package/module.

  • Dynamic load of assets/files of messages.

  • Global notification of locale change and registration/discovery of localized messages.

Usage #

A simple usage example:

  • Internationalization file msgs-en.intl:

      hello=Hello world! ## A description of the key.
    
  • Internationalization file msgs-fr.intl:

      hello=Bonjour le monde!
    
  • Dart code:

      import 'package:intl_messages/intl_messages.dart';
    
      main() async {
    
          var messages = IntlMessages.package("demo");
    
          IntlResourceDiscover discover = IntlResourceDiscover("assets/msgs-", ".intl") ;
          await messages.registerResourceDiscover(discover) ; // Default locale: 'en'. Discovered: assets/msgs-en.intl
    
          MessageBuilder msgHello = messages.msg("hello") ;
    
          print( msgHello.build() ) ; // Hello world!
    
          await messages.setLocale( 'fr' ) ; // Locale set to: 'fr'. Discovered: assets/msgs-fr.intl
    
          print( msgHello.build() ) ; // Bonjour le monde!
    
      }
    

Plurals: #

Yes we have plurals ;-)

To use plurals you should declare messages using {...} blocks with conditions zero, one, two and many and respective variable name.

Here's an example of plural usage with variable n:

  • Internationalization file msgs-en.intl:

      total_emails={zero[n]:No e-mails for \$user.|one[n]:One e-mail for \$user.|two[n]:A pair of e-mails for \$user.|many[n]:Received \$n e-mails for \$user.}
    
  • Dart code:

      import 'package:intl_messages/intl_messages.dart';
    
      main() async {
    
          var messages = IntlMessages.package("demo-plural");
    
          IntlResourceDiscover discover = IntlResourceDiscover("assets/msgs-", ".intl") ;
          await messages.registerResourceDiscover(discover) ; // Default locale: 'en'. Discovered: assets/msgs-en.intl
    
          MessageBuilder msgEmail = messages.msg("total_emails") ;
    
          print( msgEmail.build({'n': 0, 'user': 'john@mail.com'}) ) ; // No e-mails for john@mail.com.
          print( msgEmail.build({'n': 1, 'user': 'john@mail.com'}) ) ; // One e-mail for john@mail.com.
          print( msgEmail.build({'n': 2, 'user': 'john@mail.com'}) ) ; // A pair of e-mails for john@mail.com.
          print( msgEmail.build({'n': 8, 'user': 'john@mail.com'}) ) ; // Received 8 e-mails for john@mail.com.
    
      }
    

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Author #

Graciliano M. Passos: gmpassos@GitHub.

License #

Dart free & open-source license.

1.1.3 #

  • Upgrade dependencies.
    • intl: ^0.16.1
    • enum_to_string: ^1.0.8
    • swiss_knife: ^2.2.1
  • Code analysis.

1.1.2 #

  • Add Author and License to README.

1.1.1 #

  • Moved locales from swiss_knife to local source.
  • Using package resource_portable to be Web compatible.

1.1.0 #

  • Added plural block for two.
  • Added description to messages, using ## delimiter at end of message value.

1.0.0 #

  • Initial version, created by Stagehand

Use this package as a library

1. Depend on it

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


dependencies:
  intl_messages: ^1.1.3

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_messages/intl_messages.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
39
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Fix lib/src/intl_messages_base.dart. (-2.96 points)

Analysis of lib/src/intl_messages_base.dart reported 6 hints, including:

line 141 col 24: The declaration '_getDefinedLocalesCodes' isn't referenced.

line 188 col 20: Avoid empty catch blocks.

line 236 col 20: Avoid empty catch blocks.

line 422 col 24: Avoid empty catch blocks.

line 444 col 22: Avoid empty catch blocks.

Format lib/intl_messages.dart.

Run dartfmt to format lib/intl_messages.dart.

Format lib/src/locales.dart.

Run dartfmt to format lib/src/locales.dart.

Format lib/src/locales_browser.dart.

Run dartfmt to format lib/src/locales_browser.dart.

Format lib/src/locales_generic.dart.

Run dartfmt to format lib/src/locales_generic.dart.

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_messages.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
enum_to_string ^1.0.8 1.0.8
intl ^0.16.1 0.16.1
resource_portable ^2.1.6 2.1.6
swiss_knife ^2.2.1 2.2.1
Transitive dependencies
path 1.6.4
typed_data 1.1.6
Dev dependencies
pedantic ^1.8.0
test ^1.6.0