translations_keychain 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 48

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:

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.

[0.0.3] - New property builder #

  • Add support for gender and plural for easy_localization
  • Add support for JSON keys with symbols
  • Add support for JSON keys with spaces
  • Add support for JSON keys with number as first char

[0.0.2] - New default class name #

  • Default class name moved to TranslationsKeychain
  • Example project provided

[0.0.1] - First stable version #

  • Generates abstract class from JSON file
  • Default values configured

example/lib/example.dart

library example;

import 'package:example/i18n/translations_keychain.dart';

void main() {
  // Simple label
  print(TranslationsKeychain.HELLO);

  // Label with numbers
  print(TranslationsKeychain.A_123);

  // Label with spaces
  print(TranslationsKeychain.LABEL_WITH_SPACES);

  // Label with symbols
  print(TranslationsKeychain.LABEL_WITH_SYMBOLS);

  // Label with pluralization with [easy_localization] package
  // print(TranslationsKeychain.CLICKED.plural(counter));
}

Use this package as a library

1. Depend on it

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


dependencies:
  translations_keychain: ^0.0.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:translations_keychain/translations_keychain.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
1
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:translations_keychain/translations_keychain.dartpackage:translations_keychain/src/keychain_generator.dartpackage:build/build.dartpackage:build/src/generate/run_post_process_builder.dartpackage:build/src/builder/post_process_builder.dartpackage:build/src/builder/builder.dartpackage:build/src/builder/build_step.dartpackage:build/src/asset/reader.dartpackage:glob/glob.dartpackage:glob/src/list_tree.dartpackage:glob/src/io.dartpackage:glob/src/io_export.dartdart:io

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:translations_keychain/translations_keychain.dartpackage:translations_keychain/src/keychain_generator.dartpackage:build/build.dartpackage:build/src/generate/run_post_process_builder.dartpackage:build/src/builder/post_process_builder.dartpackage:build/src/builder/builder.dartpackage:build/src/builder/build_step.dartpackage:build/src/asset/reader.dartpackage:glob/glob.dartpackage:glob/src/list_tree.dartpackage:glob/src/io.dartpackage:glob/src/io_export.dartdart:io

Health suggestions

Fix lib/src/keychain_generator.dart. (-0.50 points)

Analysis of lib/src/keychain_generator.dart reported 1 hint:

line 79 col 17: Avoid empty catch blocks.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
basic_utils ^2.5.3 2.5.4
build ^1.2.2 1.3.0
glob ^1.2.0 1.2.0
path ^1.7.0 1.7.0
Transitive dependencies
_fe_analyzer_shared 5.0.0
analyzer 0.39.11
args 1.6.0
asn1lib 0.6.5
async 2.4.1
charcode 1.1.3
collection 1.14.13
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
html 0.14.0+3
http 0.12.1
http_parser 3.1.4
intl 0.16.1
js 0.6.2
json_annotation 3.0.1
logging 0.11.4
meta 1.1.8
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
pointycastle 1.0.2
pub_semver 1.4.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
build_config ^0.4.2
build_runner ^1.8.1
pedantic ^1.9.0 1.9.0 1.9.1