-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
Refactor "gen-l10n" command to use same code path when "l10n.yaml" is present or not present #125429
Conversation
command to use same code path when
l10n.yaml` is present or not present
packages/flutter_tools/lib/src/commands/generate_localizations.dart
Outdated
Show resolved
Hide resolved
} | ||
|
||
// Run the localizations generator. | ||
final LocalizationsGenerator generator = generateLocalizations( |
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.
Why are we no longer catching L10nException
? Does this get caught somewhere else?
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.
Yep, this already happens in generateLocalizations
.
bool? format, | ||
bool? useEscaping, | ||
bool? suppressWarnings, | ||
}) : arbDir = arbDir ?? globals.fs.path.join('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.
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
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.
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.
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.
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
.
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
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.
|
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
…yaml" is present or not present (flutter/flutter#125429)
I think this is a long needed change to the
gen-l10n
command. Essentially, the arguments toflutter gen-l10n
can be provided by two different methods: via command line arguments or via thel10n.yaml
file. The existence of al10n.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.LocalizationOptions
's constructor (or inargParser.addOption(...)
in the case a boolean value needs to be explicitly true).parseLocalizationsOptionsFromCommand
function to parse arguments.LocalizationOptions
at the beginning ofrunCommand()
and pass it togenerateLocalizations
.Fixes #120023.