json_locale_generator 0.0.1 copy "json_locale_generator: ^0.0.1" to clipboard
json_locale_generator: ^0.0.1 copied to clipboard

outdated

A generation tool that builds a class to get your json locale paths from dart code

A generation tool that builds a class to get your json locale paths from dart code.

Features #

Converts a json such as

{
  "ok": "OK",
  "core": {
    "app_name": "WordSing Battle"
  },
  "home": {
    "title": "No card in the deck"
  }
}

To dart code where each path can be accessed easily. For above example, doing GeneratedClass.core.app_name will return the String 'core.app_name'

Getting started #

  1. Add dependencies in your pubspec.yaml:
dev_dependencies:
  json_locale_generator: ^0.0.1
  build_runner: ^2.0.4
  1. Configure the json files to generate code for in your pubspec.yaml:
json_to_dart:
  sample_files:
    # The file assets/en.json will be converted to dart code and values can be accessed via the Locale class
    - source: assets/en.json 
      class_name: Locale 
    - source: assets/other.json
      class_name: Other
  1. Execute [dart|flutter] pub run build_runner build or [dart|flutter] pub run json_locale_generator:generate to run only json_locale_generator without other eventual builder packages. The file jsons.dart will be generated into lib/jsons.dart
  2. Import jsons.dart and start using it:
import 'jsons.dart';
FlutterI18n.translate(context, Locale.core.app_title);
1
likes
0
points
131
downloads

Publisher

verified publisherreblochor.dev

Weekly Downloads

A generation tool that builds a class to get your json locale paths from dart code

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

args, build, build_config, collection, glob, path, recase, yaml

More

Packages that depend on json_locale_generator