langen 0.0.5 copy "langen: ^0.0.5" to clipboard
langen: ^0.0.5 copied to clipboard

A simple package to generate language json keys to Dart Strings

Langen #

A simple package to generate language json keys to Dart Strings.

Overview #

Sometimes, we need to use Localization in our apps. But it is difficult and time wasted to look at and take json key in language json files. This package is developed to solve this problem. It will generate new lang_keys.dart file where all keys from all language json files are collected.

Usage #

First of all, make sure you have added the following dependencies:

dev_dependencies:
  build_runner: ^1.9.0
  langen: ^0.0.5

Run flutter pub get to get dependencies.

Then, you should add directory called langs to locate language jsons. langen will automatically search for this folder and handle generation.

Make sure you have added language jsons - for example, en.json, az.json, etc to langs folder. And make sure that you have filled language jsons correctly.

az.json

{
    "hi": "Salam",
    "bye": "Sağol"
}

en.json

{
    "hi": "Hello",
    "bye": "Bye",
    "test": "test"
}

Then, you should add 2 nested directories to lib directory - utils/constants/. Because, langen generates keys to constants directory located in lib/utils/constants.

And last step, run the following command to generate your file:

flutter pub run build_runner build

If you want to enable generation for next steps (when you add new keys and values to language jsons), you can run the following command:

flutter pub run build_runner watch

They will generate language_keys.dart file like following:

 const String hi = 'hi';

 const String bye = 'bye';

 const String test = 'test';

Then you can use this keys in anywhere you want to call by key and translate it.

Dart Versions #

  • Dart 2: ">= 2.7.0 <3.0.0"

Maintainers #

1
likes
30
pub points
0%
popularity

Publisher

unverified uploader

A simple package to generate language json keys to Dart Strings

Repository (GitHub)
View/report issues

License

BSD-2-Clause (LICENSE)

Dependencies

build, flutter

More

Packages that depend on langen