Skip to content

Conversation

@thkim1011
Copy link
Contributor

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.

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Aug 8, 2023
generateDartPluginRegistry: true,
);
final BuildResult result = await globals.buildSystem.build(
const GenerateLocalizationsTarget(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions:

  1. what's the difference between building the GenerateLocalizationsTarget() and calling generateLocalizationsSyntheticPackage()? From looking at the code it seems like the latter just runs a few extra validations, then calls the former.
  2. 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?

Copy link
Contributor Author

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

Copy link
Contributor

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:

  1. flutter_app_a
  2. flutter_app_b
  3. 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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks

Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thkim1011 thkim1011 added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 18, 2023
@auto-submit auto-submit bot merged commit 312ef54 into flutter:master Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 15, 2023
@bugrevealingbme
Copy link

Output-dir still not working in the package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[gen-l10n] Setting synthetic-package to false doesn't regenerate localizations on flutter pub get

3 participants