locale_gen 4.0.0
locale_gen: ^4.0.0 copied to clipboard

Dart tool that will convert your default locale json to dart code.

flutter locale gen #

Dart tool that will convert your default locale json to dart code.

pub package Build Status Coverage Status MIT license

Example #

Example

Setup #

Add dependency to pubspec #

pub package

dev-dependencies:
  locale_gen: <latest-version>

Add config to pubspec #

Add your locale folder to the assets to make use all your translations are loaded.

flutter:
  assets:
    - assets/locale/

Add the local_gen config to generate your dart code from json files

locale_gen:
  default_language: 'nl'
  languages: ['en', 'nl']
  locale_assets_path: 'assets/locale/' #This is the location where your json files should be saved.
  assets_path: 'assets/locale/' #This is the location where your json files are located in your flutter app.
  doc_languages: ['en'] #Only generate docs for the given languages. Defaults to all languages. An empty list will skip doc generation

Run package with Flutter #

flutter packages pub run locale_gen

Run package with Dart #

pub run locale_gen

Arguments #

Arguments are supported as of 0.1.0

You can pass a String or a num to as an argument.

Formatting for String: %1$s Formatting for num: %1$d

The number in between % and $ indicate the index of the argument. It is possible to place an argument in 1 language first but in another second:

ex (Grammatically incorrect but it makes my point):

nl '%1$s, ik woon in %2$s. Wist je dat niet?' => KOEN, ik woon in ANTWERPEN. Wist je dat niet?

fr 'I live in %2$s. You didn't knew that %1$s?" => I live in ANTWERP. You didn't knew that KOEN?

Working on mac? #

add this to you .bash_profile

flutterlocalegen(){
 flutter packages get && flutter packages pub run locale_gen
}

now you can use the locale_gen with a single command.

flutterlocalegen

Example #

This repo contains an example how to use this package.

Packages used:

  • flutter_localizations
  • shared_preferences
  • provider
  • kiwi

Other packges based on locale_gen #

  • icapps_translations
3
likes
110
pub points
40%
popularity

Publisher

vanlooverenkoen.be

Dart tool that will convert your default locale json to dart code.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

intl, meta, path, yaml

More

Packages that depend on locale_gen