o_i18n_generator 0.1.1 o_i18n_generator: ^0.1.1 copied to clipboard
Collects and merges translation files.
Description #
Merges [language-tag].json files from given path in root and all dependant packages. Creates a map with translations. You can redirect (from one key to another), overwrite and fill missing translations with values from default language.
Implementation #
Visit pub.dev -> install.
Preparing .json
files #
- Files containing translations must have names (case sensitive) like keys from language_tags.dart.
- Files must contain only correct Map. For example:
{'foo': 'bar', 'deeper_example': {'deeper_key': 'deeper_value'}, 'test': '-->deeper_example.deeper_key'}
Translation redirecting "-->" #
As you probably notice above, you can get translation from another key. All you need to do is to add "-->" at the beginning of a value and after that (without any space) a key of a source value. If the source value is nested, you have to join all keys which lead to the value by a dot.
Overwriting translations #
You can overwrite a translation from each package. You just need to add overwriting translation to assets/i18n
directory.
Remember, filename must be the same as language tag you want to overwrite.
How to use #
- Do not place or modify your files in given target directory. The script removes its content every time.
- Place
.json
files in source dir (by default:lib/src/i18n
). - Run the command below in the root directory of your project:
pub run o_i18n_generator
- In order to see default values and help, just run:
pub run o_i18n_generator --help
What files are generated? #
You can choose output-extension
. By default it is dart
. But you can select json
either.
If you want to generate dart
files, command generates files containing a map (name of map is language tag from language_tags.dart but without a dash) of translations.
Besides it generates LocaleLoader
class, which contains all supported language tags and helps to load translation map easily.
Commercial Use #
If you use this code in commercial project, please donate me via GitHub Sponsors. I do the same for packages which I use, because it ensures stable development for all of us!