-
Notifications
You must be signed in to change notification settings - Fork 28.8k
[gen_l10n] Warn users when placeholder types are converted to 'num' when using pluralization #108036
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
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
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.
You can ask @Hixie for a "test exemption" however it might be simplest to just include one.
if (message.isPlural) { | ||
final Placeholder countPlaceholder = message.getCountPlaceholder(); | ||
if (countPlaceholder.type != null && countPlaceholder.type != 'num') { | ||
logger.printWarning("Placeholders for plurals are automatically converted to type 'num'."); |
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.
It may be difficult for the developer to correlate this warning with a specific message. It would be helpful to include the name of the message and the name of the parameter in the warning.
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.
Fixed!
Hey @HansMuller, I just made the change you recommended, added a test (turns out testing logs are not too bad), and fixed up the rest of the tests that were affected by changing the |
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.
The bots noticed some trailing spaces. Other than that and a trivial point about a comment, this is ready to land.
@@ -1141,6 +1148,22 @@ class LocalizationsGenerator { | |||
); | |||
}); | |||
|
|||
// Warn users when placeholder types are overrided to 'num'. |
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.
This comment probably isn't necessary; at the moment it doesn't describe the entire block.
@@ -1141,6 +1148,22 @@ class LocalizationsGenerator { | |||
); | |||
}); | |||
|
|||
// Warn users when placeholder types are overrided to 'num'. | |||
for (final Message message in messages) { | |||
if (message.isPlural) { |
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.
These tests/warnings are great.
|
|
… 'num' when using pluralization (flutter/flutter#108036)
… 'num' when using pluralization (flutter/flutter#108036)
…hen using pluralization (flutter#108036) * init * asdf * fix tests * change warning slightly * fix test again * fix spacing and comment * fix lint
See title. This PR refactors logging so that the logger is saved as an instance variable of the
LocalizationsGenerator
class, and adds a warning when there is a pluralization placeholder whose type isn't num.Fixes #98868
Tested locally:
I didn't think I needed to add tests here since there's really no change other than logging.