-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[flutter_tools] Generate localizations on flutter pub get #132172
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
[flutter_tools] Generate localizations on flutter pub get #132172
Conversation
| generateDartPluginRegistry: true, | ||
| ); | ||
| final BuildResult result = await globals.buildSystem.build( | ||
| const GenerateLocalizationsTarget(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions:
- what's the difference between building the
GenerateLocalizationsTarget()and callinggenerateLocalizationsSyntheticPackage()? From looking at the code it seems like the latter just runs a few extra validations, then calls the former. - Maybe I don't understand this synthetic package, but why would you want to opt out of the synthetic package and yet still have localizations generated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synthetic package creates a "fake dart package" in .dart_tool/flutter_gen by adding the package to .dart_tool/package_config.json. But because of the way this is set up, it prevents users from exporting anything from the synthetic package (see #109606).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So is the idea that I have:
- flutter_app_a
- flutter_app_b
- localization_shared_package_c
The localizations all live in C, which A and B both depend on. So apps A and B both have synthetic-package: false, since they will be depending on real package C. But this PR will ensure running flutter pub get from A or B will still re-generate the localization files in C.
Is this right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is the case, but why the synthetic-package flag is necessary (necessary because it prevents developers from exporting localization files) is separate from the purpose of this PR, which is to make sure that gen_l10n gets run in flutter pub get whether the synthetic-package flag is on or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but to understand the need for this change, I'm trying to understand why we even allow opting out of synthetic-package, since my understanding was that we relied on the synthetic package for localizations to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opting out of synthetic-package puts the generated files in the same project under /lib/l10n.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks
christopherfujino
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Output-dir still not working in the package |
Currently, flutter pub get generates localizations if there exists an l10n.yaml file where synthetic-package is not false. However, for any user who needs to turn off synthetic-package, their localizations are not generated. This PR should make the behavior more consistent. (Also it seems good to make it so that running flutter pub get once resolves all the dependencies so that people can get to work without running flutter gen-l10n manually.)
Fixes #84979.