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

Getting started

  1. Add dependencies in your pubspec.yaml:

  json_locale_generator: ^0.0.3
  build_runner: ^2.0.4
  1. Configure the json files to generate code for in your pubspec.yaml:

    # 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);


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'


View Github