cph-cachet / research.package

A Flutter package implementing support for surveys like ResearchStack and ResearchKit
MIT License
51 stars 43 forks source link

unable to add another language to RPLocalizations in research_package 0.6.6 #54

Closed appliedrd closed 2 years ago

appliedrd commented 2 years ago

research_package 0.6.6 runing on android pixel 5 1) create a new flutter project with research.package/example/ 2) duplicate da.json to fr.json to assets folder and pubspec.yaml 3) in main.dart , add Locale('fr') to supportedLocales: [ ]

test 1 in main.dart, change if (supportedLocale.languageCode == locale!.languageCode) to if (supportedLocale.languageCode == "da"). debug flutter. app runs successfully in german

test 2 in main.dart, change if (supportedLocale.languageCode == locale!.languageCode) to if (supportedLocale.languageCode == "fr"). app throws exception

console: Syncing files to device Pixel 5... I/flutter (17886): AssetLocalizations - loading 'assets/lang/fr.json' I/flutter (17886): RPLocalizations - loading 'packages/research_package/assets/lang/fr.json' Screenshot from 2021-11-02 18-15-52

asset_bundle.dart line 224: throw FlutterError('Unable to load asset: $key');

and $key is packages/research_package/assets/lang/fr.json

this should be assets/lang/fr.json, right?

this worked correctly in research_package 0.4.1 . For now, I will revert back

love this package!!!! great job. Ted

appliedrd commented 2 years ago

looks like I just don't understand the changes to RPLocalization introduced in 0.5.4. can you provide an example of adding a 3rd language to your example which? I would really lie to use null safety

appliedrd commented 2 years ago

temporary fix in RPLocalization.dart

line 13 class RPLocalizations extends AssetLocalizations { //static final String assetPath = 'research_package/assets/lang'; static final String assetPath = 'assets/lang';

line 28 // String get staticAssetName => // 'packages/$assetPath/${locale.languageCode}.json'; String get staticAssetName => '$assetPath/${locale.languageCode}.json';

bardram commented 2 years ago

Hi @appliedrd - this seems wrong. I will look into this as soon as I can get back to the code - your suggestion seems right. Thanks for reporting it.

You are also most welcome to make a pull request if you already fixed it?

bardram commented 2 years ago

This issue has now been addressed and published in version 0.7.1.

There were some misunderstandin on how RP localization works in the issue above, so I've also create a tutorial which explains RP Localization