Skip to content

A Dart builder to convert the JSON translation files into an abstract class for label suggestions

License

Notifications You must be signed in to change notification settings

lcaprini/translations_keychain

Repository files navigation

translations_keychain

translations_keychain is a small Dart builder that converts the local JSON files used for translations into a Dart abstract class.

When translations_keychain is running in watch mode, you could simply edit your JSON file and the abstract class will be automatically updated.

Features

  • Merges all JSON keys in one single file
  • Supports for nested JSON objects for grouped labels
  • Sorts the final class properties
  • Use UpperCamelCase for class name and snake_case for file name

Getting Started

Install

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

dev_dependencies:
  # stable version install from https://pub.dev/packages
  translations_keychain: <last_version>
  build_runner: ^1.8.1

  # Dev version install from git REPO
  translations_keychain:
    git: https://github.com/lcaprini/translations_keychain.git

Configure

By default translations_keychain scans every JSON file into the /assets/langs directory and generates the translations_keychain.dart file into /lib/i18n directory.

If you want to change the default behaviour you could create or update the build.yaml file of your project with:

targets:
  $default:
    builders:
      translations_keychain:
        options:
          path: <langs_assets_directory>
          output: <output_directory>
          class_name: <class_and_file_name>

Use with Dart

With build_runner installed, you could semply launch the build task

pub run build_runner build --delete-conflicting-outputs

or launch in watch mode if you want to update the final class file automagically.

pub run build_runner watch --delete-conflicting-outputs

Use with Flutter

Of course this package could be used also in a flutter app; the build_runner tasks became:

flutter pub run build_runner build --delete-conflicting-outputs

flutter pub run build_runner watch --delete-conflicting-outputs

Example

An example showing how to setup and use translations_keychain.

About

A Dart builder to convert the JSON translation files into an abstract class for label suggestions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages