Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lcaprini/translations_keychain

A Dart builder to convert the JSON translation files into an abstract class for label suggestions
https://github.com/lcaprini/translations_keychain

builder builder-generator dart flutter i18n

Last synced: 30 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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

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

## Getting Started

### Install

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

```yaml
dev_dependencies:
# stable version install from https://pub.dev/packages
translations_keychain:
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:

```yaml
targets:
$default:
builders:
translations_keychain:
options:
path:
output:
class_name:
```

### Use with Dart

With `build_runner` installed, you could semply launch the `build` task

```bash
pub run build_runner build --delete-conflicting-outputs
```

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

```bash
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:

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

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

### Example

- [Source code](example)

An example showing how to setup and use `translations_keychain`.