Skip to content

Conversation

@perclasson
Copy link
Contributor

@perclasson perclasson commented Apr 7, 2020

Description

Handle single quotes, double quotes and dollar signs in strings for gen_l10n script.

Related Issues

Closes #54184
Closes #54203

Tests

I updated the following tests:

  • generated l10n classes produce expected localized strings

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.

@fluttergithubbot fluttergithubbot added c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels. labels Apr 7, 2020
@perclasson perclasson changed the title [gen_l10n] Handle quotes and double quotes in plural strings [gen_l10n] Handle single and double quotes in plural strings Apr 7, 2020
}
}
pluralLogicArgs.add(" ${pluralIds[pluralKey]}: '$argValue'");
pluralLogicArgs.add(' ${pluralIds[pluralKey]}: ${generateString(argValue, escapeDollar: false)}');
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize that this is intended to behave mostly the way the existing code behaved. Are we missing another error here? What about a plural that contains dollar signs?

"singleQuotePlural": "{count,plural, $ =1{Flutter's amazing $, times 1!} other{Flutter's amazing $, times {count}!}}",

Copy link
Contributor

Choose a reason for hiding this comment

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

@HansMuller Did you mean something like:

"dollarSignPlural": "{count,plural, =1{Flutter's amazing $, times {count}!} other{Flutter's amazing $, times {count}!}}",

I think the current way generateString works, it doesn't properly account for $ correctly because we use $ in the generated strings to interpolate variables into the messages. I'll file a separate issue for this, but we should unblock having this work for the other special JSON characters like quotes, return carriage, etc for now.

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 by moving up the generateString function to before we do the interpolation of the variables, we can fix this. But it's probably best to handle it in a separate issue and add the extra test coverage that is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Created the issue here: #54203, had a discussion with @perclasson via DM -- We can solve the issue and add test coverage for it in the same PR. We would probably want to change the PR title and description to reflect the fixes this would address

@perclasson perclasson changed the title [gen_l10n] Handle single and double quotes in plural strings [gen_l10n] Handle single, double quotes, and dollar signs in strings Apr 7, 2020
Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for figuring this one out!

@fluttergithubbot fluttergithubbot merged commit e8d2907 into flutter:master Apr 7, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. 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] Cannot use dollar sign in ARB messages [gen_l10n] Localizations fail to generate with apostrophes or quotes in plural strings

6 participants