flutter_gen icon indicating copy to clipboard operation
flutter_gen copied to clipboard

Json to strings.dart

Open Tkko opened this issue 2 years ago • 6 comments

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';
}

Tkko avatar May 15 '22 07:05 Tkko

Related to #224

Tkko avatar May 15 '22 07:05 Tkko

@wasabeef Any thought about this?

Tkko avatar May 31 '22 06:05 Tkko

@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.

wasabeef avatar Jun 01 '22 03:06 wasabeef

@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 avatar Jun 01 '22 19:06 Tkko

@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'),

thangnc avatar Sep 18 '22 13:09 thangnc

Converting this to a draft since it has unaddressed conflicts and comments. @Tkko If you are still on this, please make corresponding changes. Thanks!

AlexV525 avatar Nov 04 '23 02:11 AlexV525

Please make new requests if you still on this.

AlexV525 avatar Mar 10 '24 07:03 AlexV525