Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple package project #23

Open
remonh87 opened this issue Feb 16, 2019 · 11 comments
Open

Add support for multiple package project #23

remonh87 opened this issue Feb 16, 2019 · 11 comments
Labels
enhancement New feature or request
Milestone

Comments

@remonh87
Copy link

Is your feature request related to a problem? Please describe.
This library really works great and generates a lot of boiler plate code. Unfortunately it works perfect for a single package app but does not support monorepo. For example:
I have a package called app_ui and my translation assets are located in: lib/app_ui/translations. In the pubspec.yaml I declare my assets like: packages/app_ui/i18n/en.json . My main is located in the app_main package.
The rosetta generator is able to find my file, can generate the code, but does not generate the proper code for loading the asset. When I start the app it crashes because rootbundle cannot load the translated file.

Describe the solution you'd like
Add support for the package name, for example:
@Stone(path: 'lib/i18n', package: "app_ui") class Translation with _$TranslationHelper { ... }

Based on this the rosetta_generator can generate the following snippet in the translationhelper:
var jsonStr = await rootBundle.loadString("packages/app_ui/i18n/${locale.languageCode}.json");

@remonh87 remonh87 changed the title Add support for multiple packages Add support for multiple package project Feb 16, 2019
@agta1991 agta1991 self-assigned this Feb 18, 2019
@agta1991 agta1991 added the enhancement New feature or request label Feb 18, 2019
@agta1991
Copy link
Contributor

This sounds like a great feature for the next version.

Can you provide a simple detailed project setup, where the described issue is reproducible? I got a bit confused when trying to declare the assets in the multi package setup.

@remonh87
Copy link
Author

I have an example setup at my github: https://github.com/remonh87/multi-package-example-flutter

@agta1991
Copy link
Contributor

agta1991 commented Feb 19, 2019

So if I get it correctly, you have an app packages which uses a separate app_ui flutter package, which contains the translation json-s and the @Stone-ed class.
Did you declare and run the generator for the app or the ui package?

@remonh87
Copy link
Author

the generator is declared and run within the ui package

@agta1991
Copy link
Contributor

Awesome! I checked a few configurations to get a bigger picture about the problem.

Tomorrow, I will have some time to add the new functionality to the lib.

agta1991 pushed a commit that referenced this issue Feb 24, 2019
Issue #23

Optional `package` attribute added for `Stone` annotation.
agta1991 pushed a commit that referenced this issue Feb 24, 2019
@agta1991 agta1991 added this to the v0.1.2 milestone Feb 24, 2019
@agta1991
Copy link
Contributor

As described, v0.1.2 release introduces the package attribute to declare the bundle package.
It's published to pub so you can try out the new API.

@remonh87
Copy link
Author

@agta1991 thanks for picking this up quickly. I did test it with the latest package but still see a small issue in the generated code of the helper: you include the lib folder in the call to rootbundle. This should not be the case when you want to load the asset from a package.

Example
var jsonStr = await rootBundle.loadString('packages/app_ui/lib/i18n/${locale.languageCode}.json');

should become:
var jsonStr = await rootBundle.loadString('packages/app_ui/i18n/${locale.languageCode}.json');

@agta1991
Copy link
Contributor

agta1991 commented Feb 28, 2019

This brings back another problem. The generator should know the path of the json in the builder host's file system during the build phase, but also it must know the package path which will be bundled.
In the above case it is different. I used it in separate folders in my sandbox project, which resulted in matching host and bundled paths. Moving the i18n folder up into the parent of lib will result in this case.

As I saw in your example project setup, the i18n folder is under lib. And you declare it as

flutter:
  assets:
  - packages/app_ui/i18n/en.json

But if you put it next to lib, and declare it as:

flutter:
  assets:
  - i18n/en.json

The compiler will still bundle it as packages/app_ui/i18n/en.json but it will have a matching path "i18n/en.json" with the host system.

Is it critical to support mixing the asset files with the source files in lib?

@spkersten
Copy link

spkersten commented Feb 28, 2019

@agta1991 I don't think it's critical for us. Reading the docs it seems like putting them into the root of the package is actually the right way and putting them into lib was a misunderstanding by us.

@remonh87
Copy link
Author

remonh87 commented Mar 5, 2019

It is indeed not critical so issue can be closed.

@remonh87 remonh87 closed this as completed Mar 5, 2019
@remonh87 remonh87 reopened this Jun 28, 2019
@remonh87
Copy link
Author

remonh87 commented Jun 28, 2019

I used the suggested structure but then the rosetta generator cannot find the file and won't generate the keys: see for example https://github.com/remonh87/multi-package-example-flutter .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants