flutter_gen
flutter_gen copied to clipboard
Json to strings.dart
What does this change?
Many developers use json based translations, this PR adds strings.dart class generator from json files.
pubspec.yaml
flutter_gen:
output: lib/gen/
line_length: 80
strings:
enabled: true
class_name: Strings
inputs:
- assets/translations/en.json
run: flutter packages pub run build_runner build
From en.json:
{
"appTitle": "Title",
"contributor": "Tornike Kurdadze (Tkko)"
}
To strings.gen.dart
class Strings {
Strings._();
static const appTitle = 'appTitle';
static const contributor = 'contributor';
}
Related to #224
@wasabeef Any thought about this?
@Tkko Thank you for your PR. Could you tell me a little more about the use case? In general, I think We're using flutter_localizations.
@Tkko Thank you for your PR. Could you tell me a little more about the use case? In general, I think We're using flutter_localizations.
This is helpful if you are using json based localizations, checkout the article for reference. https://medium.com/@rafavinnce/flutter-internationalization-the-easy-way-using-provider-and-json-986eb5d76822
In short, you have translation files, en.json
, ka.json
, ...
and you are accessing the translated string by the key, and with this PR keys will be extracted as constants.
@Tkko Thank you for your PR. Could you tell me a little more about the use case? In general, I think We're using flutter_localizations.
This is helpful if you are using json based localizations, checkout the article for reference. https://medium.com/@rafavinnce/flutter-internationalization-the-easy-way-using-provider-and-json-986eb5d76822
In short, you have translation files,
en.json
,ka.json
,...
and you are accessing the translated string by the key, and with this PR keys will be extracted as constants.
@wasabeef The idea of this PR seems to be inspired Android localization R.string.xxx_yyy
, and the Flutter localization is using AppLocalizations.instance.text('page_one'),
Converting this to a draft since it has unaddressed conflicts and comments. @Tkko If you are still on this, please make corresponding changes. Thanks!
Please make new requests if you still on this.