json_file_generator
json_file_generator generates json file from static const string variables declared in .dart file.
The generated file i.e strings.json could be used by mojito.global Translation Management System(TMS)
Runtime Requirements
json_file_generator generates only json file. So there is no extra runtime requirement.
Usage
- Add json_file_generator as a
dev_dependency
. - Run json_file_generator on your string resource ".dart" file to generate the required JSON file
by running:
flutter pub get
thenflutter pub run json_file_generator --input <string_resource.dart file>
For example -flutter pub run json_file_generator --input lib/src/localization/string_resource.dart
. This will generate strings.json file in the same directory as string_resource.dart file.
How to define plural strings
- Create a const
plural
object as follows -class Plural { const Plural(); } const plural = Plural();
- Annotate a static const string variable with
@plural
annotation. - This will create a nested json structure as follows -
{ "{name} has {money} dollars": { "zero": "profileScreenMoneyCount", "one": "profileScreenMoneyCount", "many": "profileScreenMoneyCount", "other": "profileScreenMoneyCount" }, "Did you know?": "didYouKnow" }
Credits
Initial code for parsing a file is copied from pigeon package. https://pub.dev/packages/pigeon