Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor(compiler): trim expression whitespace when preserveSignificantWhitespace === false #58176

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

Closed
wants to merge 3 commits into from

Conversation

dgp1130
Copy link
Contributor

@dgp1130 dgp1130 commented Oct 12, 2024

This PR trims whitespace in expressions when preserveSignificantWhitespace === false. This allows messages to be a bit more durable to insignificant whitespace changes. For example, reformatting the following:

<div i18n>Hello, {{ name }}!</div>

Into:

<div i18n>Hello, {{
  name
}}!</div>

Is a whitespace-only change which has no visible effect to translators. Therefore we trim whitespace before extracting messages and normalize it to a standard format ({{name}}).

This PR also removes the functionality for ignoring placeholder expressions entirely (originally added as part of dab722f). Ideally, we wouldn't take placeholders into account at all, since whether an expression is {{foo}} or {{bar}} is also irrelevant to the translator. However doing so causes some challenges with TC, so we can't go that far just yet (see http://b/367255149#comment10). Therefore this PR rolls back that particular feature and replaces it with this one which trims expression whitespace instead.

This serializes the expression AST back into a string. This is useful to normalize whitespace in expressions so i18n messages are not affected by insignificant changes (such as going from `{{ foo }}` to `{{\n  foo\n}}`).
… `preserveSignificantWhitespace === false`.

This parses and reserializes expressions to normalize their whitespace formatting and make them more durable to insignificant changes in whitespace which might otherwise alter message IDs despite no translator-meaningful change being made.
While effective, `preservePlaceholders` unfortunately is not viable in google3 at the moment due to some complexities with how TC extracts messages. Therefore this feature is being removed in favor of whitespace trimming of expressions, which is viable for TC and provides most of the same benefit.

This is a partial revert of dab722f.
@dgp1130 dgp1130 added action: review The PR is still awaiting reviews from at least one requested reviewer area: i18n Issues related to localization and internationalization target: major This PR is targeted for the next major release area: compiler Issues related to `ngc`, Angular's template compiler labels Oct 12, 2024
@dgp1130 dgp1130 requested a review from AndrewKushnir October 12, 2024 01:54
@ngbot ngbot bot added this to the Backlog milestone Oct 12, 2024
@angular-robot angular-robot bot added area: compiler Issues related to `ngc`, Angular's template compiler and removed area: compiler Issues related to `ngc`, Angular's template compiler labels Oct 12, 2024
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @dgp1130 👍

@AndrewKushnir AndrewKushnir removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 12, 2024
@dgp1130
Copy link
Contributor Author

dgp1130 commented Oct 14, 2024

TGP (with flag disabled): http://test/OCL:685031311:BASE:685031062:1728703209245:53d763a5

I'll run another TGP with the flag enabled just to make sure enabling it won't cause any problems.

@dgp1130
Copy link
Contributor Author

dgp1130 commented Oct 15, 2024

TGP with the relevant flag enabled.

There are some XMB golden tests which failed, but that's expected because enabling the flag changes message IDs, so there's no issue. One project had a TC extraction failure due to a couple of now-duplicate messages, but we can avoid that by just adding a meaning field to disambiguate the messages before enabling the flag.

Should be good to merge!

@dgp1130 dgp1130 added the action: merge The PR is ready for merge by the caretaker label Oct 15, 2024
@devversion
Copy link
Member

This PR was merged into the repository by commit 6d33ab5.

The changes were merged into the following branches: main

devversion pushed a commit that referenced this pull request Oct 16, 2024
… `preserveSignificantWhitespace === false`. (#58176)

This parses and reserializes expressions to normalize their whitespace formatting and make them more durable to insignificant changes in whitespace which might otherwise alter message IDs despite no translator-meaningful change being made.

PR Close #58176
devversion pushed a commit that referenced this pull request Oct 16, 2024
While effective, `preservePlaceholders` unfortunately is not viable in google3 at the moment due to some complexities with how TC extracts messages. Therefore this feature is being removed in favor of whitespace trimming of expressions, which is viable for TC and provides most of the same benefit.

This is a partial revert of dab722f.

PR Close #58176
@crisbeto crisbeto mentioned this pull request Oct 16, 2024
crisbeto added a commit to crisbeto/angular that referenced this pull request Oct 16, 2024
Fixes some tests that started failing, because angular#58154 made it so placeholder-only messages are extracted while angular#58176 added some tests that only contain placeholders.
devversion pushed a commit that referenced this pull request Oct 16, 2024
Fixes some tests that started failing, because #58154 made it so placeholder-only messages are extracted while #58176 added some tests that only contain placeholders.

PR Close #58217
@dgp1130 dgp1130 deleted the trim-expressions branch October 16, 2024 16:20
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler area: i18n Issues related to localization and internationalization target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants