Skip to content

Refactor "gen-l10n" command to use same code path when "l10n.yaml" is present or not present #125429

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

Merged
merged 7 commits into from
Apr 26, 2023

Conversation

thkim1011
Copy link
Contributor

@thkim1011 thkim1011 commented Apr 24, 2023

I think this is a long needed change to the gen-l10n command. Essentially, the arguments to flutter gen-l10n can be provided by two different methods: via command line arguments or via the l10n.yaml file. The existence of a l10n.yaml file causes the latter approach to take precedence.

However, currently, there's several differences in how the two approaches are handled, and most of the default arguments are all over the place, causing unexpected issues such as #120457 or #120023.

This PR refactors the command so that

  • LocalizationOptions are more consistent with the actual argument names/yaml options.
  • All default values are determined in LocalizationOptions's constructor (or in argParser.addOption(...) in the case a boolean value needs to be explicitly true).
  • New parseLocalizationsOptionsFromCommand function to parse arguments.
  • Parse LocalizationOptions at the beginning of runCommand() and pass it to generateLocalizations.

Fixes #120023.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 24, 2023
@thkim1011 thkim1011 changed the title Refactor gen-l10n command to use same code path when l10n.yaml` is present or not present Refactor "gen-l10n" command to use same code path when "l10n.yaml" is present or not present Apr 24, 2023
}

// Run the localizations generator.
final LocalizationsGenerator generator = generateLocalizations(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we no longer catching L10nException? Does this get caught somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this already happens in generateLocalizations.

bool? format,
bool? useEscaping,
bool? suppressWarnings,
}) : arbDir = arbDir ?? globals.fs.path.join('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.

can we lift this hack to the callsite of parseLocalizationsOptionsFromYAML and make arbDir a required field here (or just restore the original behavior where this fallback is in the arg parser)? Generally, introducing a globals.dart import to a new library should be avoided. Eventually we want to ban all use of globals getters, and require them all to be direct injected from the top down: #47161

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are your thoughts on passing down globals.fs into parseLocalizationsOptionsFromYAML and parseLocalizationsOptionsFromCommand and call fileSystem.path.join('lib', 'l10n') at those two locations? I think parseLocalizationsOptionsFromYAML are used in several different locations, and I'd prefer to consolidate the default values if possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

To me hiding this fallback behavior deep in a helper function makes the overall behavior of whatever top level command that calls it more difficult to reason about, rather than lifting the fallback as high as possible and making the rest of the references to the value final.

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 Apr 26, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 26, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Apr 26, 2023

auto label is removed for flutter/flutter, pr: 125429, due to - The status or check suite Mac channels_integration_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite Mac native_ui_tests_macos has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac tool_tests_general has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac tool_integration_tests_1_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac plugin_test_ios has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac plugin_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac plugin_dependencies_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac dart_plugin_registry_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac customer_testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@thkim1011 thkim1011 merged commit 5c44b1d into flutter:master Apr 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 30, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 30, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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] Localization files are auto-generated when running the project
2 participants