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
feat(compiler): add "original" placeholder value on extracted XMB #25079
Conversation
Note: These bazel tests were already failing //packages/compiler-cli/test/compliance:compliance |
@@ -43,6 +43,7 @@ jasmine_node_test( | |||
], | |||
deps = [ | |||
":extract_i18n_lib", | |||
"//packages/common:npm_package", |
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.
Could you explain why this change is required ? Thx
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.
CommonModule is needed to process ICU syntax, otherwise angular complains that it doesn't know how to handle ICU. The module is imported in a generated "module" test file similar to @NgModule
, but CommonModule
is in a different package.
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 not importing //packages/common
instead ?
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.
I copied it from another rule, when changing it to //packages/common
, bazel fails the test //packages/compiler-cli/test:extract_i18n
because "error TS2307: Cannot find module '@angular/common'."
@Goodwine Thanks for the PR. I'll do my best to review it by Thursday. |
@@ -115,30 +115,36 @@ class _Visitor implements i18n.Visitor { | |||
} | |||
|
|||
visitTagPlaceholder(ph: i18n.TagPlaceholder, context?: any): xml.Node[] { | |||
const startEx = new xml.Tag(_EXEMPLE_TAG, {}, [new xml.Text(`<${ph.tag}>`)]); | |||
const startTagPh = new xml.Tag(_PLACEHOLDER_TAG, {name: ph.startName}, [startEx]); | |||
const originalStartTag = new xml.Text(`<${ph.tag}>`); |
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.
nit: rename to startTagAsText
or something along those line
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.
Please also add a comment explaining that the TC uses this extra text node (for all placeholder types).
if (ph.isVoid) { | ||
// void tags have no children nor closing tags | ||
return [startTagPh]; | ||
} | ||
|
||
const closeEx = new xml.Tag(_EXEMPLE_TAG, {}, [new xml.Text(`</${ph.tag}>`)]); | ||
const closeTagPh = new xml.Tag(_PLACEHOLDER_TAG, {name: ph.closeName}, [closeEx]); | ||
const originalCloseTag = new xml.Text(`</${ph.tag}>`); |
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.
nit: closeTagAsText
]); | ||
return [new xml.Tag(_PLACEHOLDER_TAG, {name: ph.name}, [exTag])]; | ||
const originalIcu = new xml.Text( | ||
`{${ph.value.expression}, ${ph.value.type}, ${Object.keys(ph.value.cases).map((value: string) => value + ' {...}').join(' ')}}`); |
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.
nit: would you mind extracting the ${}
to local const
s ?
(I know this has not been introduced by you but it would help readability anyway)
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.
will do
<msg id="703464324060964421"><source>file.ts:22,24</source> | ||
<ph name="ICU"><ex>{sex, select, male {...} female {...} other {...}}</ex></ph> | ||
<ph name="ICU"><ex>male, female, other</ex>{sex, select, male {...} female {...} other {...}}</ph> |
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.
is changing the <ex>
a requirement from the TC
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's not, <ex>
is used by translators to know what kind of values to expect, I figured it would make sense to only list the options instead of the icu's text representation
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.
I would prefer not to change this one in this PR, Coud you please revert this change.
<msg id="3780349238193953556"><source>file.ts:9</source><source>file.ts:10</source><ph name="START_ITALIC_TEXT"><ex><i></ex></ph>with placeholders<ph name="CLOSE_ITALIC_TEXT"><ex></i></ex></ph></msg> | ||
<msg id="5415448997399451992"><source>file.ts:11</source><ph name="START_TAG_DIV"><ex><div></ex></ph>with <ph name="START_TAG_DIV"><ex><div></ex></ph>nested<ph name="CLOSE_TAG_DIV"><ex></div></ex></ph> placeholders<ph name="CLOSE_TAG_DIV"><ex></div></ex></ph></msg> | ||
<msg id="3780349238193953556"><source>file.ts:9</source><source>file.ts:10</source><ph name="START_ITALIC_TEXT"><ex><i></ex><i></ph>with placeholders<ph name="CLOSE_ITALIC_TEXT"><ex></i></ex></i></ph></msg> | ||
<msg id="5415448997399451992"><source>file.ts:11</source><ph name="START_TAG_DIV"><ex><div></ex><div></ph>with <ph name="START_TAG_DIV"><ex><div></ex><div></ph>nested<ph name="CLOSE_TAG_DIV"><ex></div></ex></div></ph> placeholders<ph name="CLOSE_TAG_DIV"><ex></div></ex></div></ph></msg> |
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.
<div>
looks wrong here - is it github transforming encoded entities ?
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 is the XML library when doing new xml.Text(`<${ph.tag}>`);
, it's WAI
+100,000,000 this will eliminate an enormous annoyance |
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.
Thank you very much for this PR.
Could you please address the minor comments ?
Thanks for the review, I've addressed the comments, PTAL |
Could you please revert the edit:
|
Update XMB placeholders(<ph>) to include the original value on top of an example. Placeholders can by definition have one example(<ex>) tag and a text node. The text node is used by TC as the "original" value from the placeholder, while the example should represent a dummy value. For example: <ph name="PET"><ex>Gopher</ex>{{ petName }}</ph>. This change makes sure that we have the original text, but it *DOES NOT* make sure that the example is correct. The example has the same wrong behavior of showing the interpolation text rather than a useful example. No breaking changes, but tools that depend on the previous behavior and don't consider the full XMB definition may fail to parse the XMB. Fixes b/72565847
PTAL |
merge-assistance: missing pullapprove but the change is only about a symbol that has been renamed (to fix a typo). Please merge. Thanks. |
…gular#25079) Update XMB placeholders(<ph>) to include the original value on top of an example. Placeholders can by definition have one example(<ex>) tag and a text node. The text node is used by TC as the "original" value from the placeholder, while the example should represent a dummy value. For example: <ph name="PET"><ex>Gopher</ex>{{ petName }}</ph>. This change makes sure that we have the original text, but it *DOES NOT* make sure that the example is correct. The example has the same wrong behavior of showing the interpolation text rather than a useful example. No breaking changes, but tools that depend on the previous behavior and don't consider the full XMB definition may fail to parse the XMB. Fixes b/72565847 PR Close angular#25079
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Update XMB placeholders(
<ph>
) to include the original value on top of anexample. Placeholders can by definition have one example(
<ex>
) tag and atext node. The text node is used by TC as the "original" value from the
placeholder, while the example should represent a dummy value.
For example:
<ph name="PET"><ex>Gopher</ex>{{ petName }}</ph>
.This change makes sure that we have the original text, but it DOES NOT
make sure that the example is correct. The example has the same wrong
behavior of showing the interpolation text rather than a useful example.
No breaking changes, but tools that depend on the previous behavior and
don't consider the full XMB definition may fail to parse the XMB.
Fixes b/72565847
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
A message like
<foo>Name: {{yourName}}</foo>
would generate this xmb message:Issue Number: http://b/72565847
What is the new behavior?
A message like
<foo>Name: {{yourName}}</foo>
would generate this xmb message:The
<ph>
PCDATA (text node) is used by TC for some validations explained further in the internal bug.Does this PR introduce a breaking change?
Tools that depend on the current (wrong) implementation may fail if they don't take the
#PCDATA
definition into account.Other information
Ideally the example should be something like
<ex>Carlos</ex>
, but fixing the example is out of scope because there is no way to provide one.