intl_messages 2.1.14 copy "intl_messages: ^2.1.14" to clipboard
intl_messages: ^2.1.14 copied to clipboard

Simple and easy internationalization and localization messages framework for Dart (integrated with package 'intl') and translation tools (integrated with OpenAI and ChatGPT).

intl_messages #

pub package Null Safety Dart CI GitHub Tag New Commits Last Commits Pull Requests Code size License

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.

  • Translation tools (including integration with OpenAI and ChatGPT).

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.
      
    }
    

CLI Tool #

You can use the intl_messages CLI tool:

Check an .intl file using a reference file:

  $> intl_messages check --ref msgs-en.intl -f msgs-fr.intl

Format an .intl file entries using a reference file:

  $> intl_messages format --ref msgs-en.intl -f msgs-fr.intl --overwrite

Fix an .intl file using a reference file and OpenAI (ChatGPT):

  $> intl_messages fix --ref msgs-en.intl -f msgs-fr.intl -t openai --overwrite

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.

4
likes
0
pub points
79%
popularity

Publisher

unverified uploader

Simple and easy internationalization and localization messages framework for Dart (integrated with package 'intl') and translation tools (integrated with OpenAI and ChatGPT).

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

args, async_extension, collection, dart_openai, enum_to_string, intl, path, resource_portable, swiss_knife, yaml

More

Packages that depend on intl_messages