-
Notifications
You must be signed in to change notification settings - Fork 881
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
[localize-tools] Validation of existing translation should not fail on changed expression #4502
Comments
According to the comment here lit/packages/localize-tools/src/messages.ts Lines 108 to 119 in 546d75d
But perhaps this assumption doesn't hold when we consider multiple source Need to investigate and consider this more carefully. |
Found some more context here: #2405 (comment) The churn in extraction was anticipated but looks like we didn't really handle that at the time, only addressing the more pressing problem with making sure the correct expressions are used in transform mode. In the PR above, we decided to treat same id with the same description as canonically the same translation unit. Firstly, this should be made clear in the docs in lit.dev. Secondly, I think we need to update the validation function lit/packages/localize-tools/src/messages.ts Line 120 in 546d75d
to match this behavior so we just check for the placeholder count. Might we need to also check for description in a <note from="lit-localize"> ? If so, changing the description, or adding a new one, might cause error and churn.
Another concern with this is we would no longer check equiv-text for discrepancy.. I think the comment above might be outdated with regards to it being "substituted back into generated executable source code", so perhaps there's no need to really check that. Need to confirm this. If we make these pass validation, I think the extract will end up overwriting the previous |
extract
validation of existing translation should not fail on changed expression
Got around to trying out some things and (re)discovering how lit-localize actually works. Thought dump here so I don't forget it all later. When running The validation and potential error happens when For runtime mode, it looks like localize currently uses the placeholder text from the For transform mode, localize only uses the index of the placeholder from Potential forward path here, we can make runtime mode behave like transform in that it'll always source placeholder text from source code. This removes the concern from the original comment above of arbitrary code injection from the translation targets. The only useful validation we'd really need then is just the number of placeholders so we know where to place them. But without content validation, we won't detect any drift from source code to translation target for cases were the id was manually made. Would that actually matter? (This kind of drift wouldn't exactly happen with auto generated ID as it would be treated as a new translation unit then) We could make the validation specifically ignore the expression (everything inside |
Opted to implement
This required the smallest change with the correct behavior. |
Which package(s) are affected?
Localize (@lit/localize)
Description
Reported by @kensternberg-authentik in #4489
https://lit.dev/docs/localization/overview/#message-ids states the rules for message id generation and how they're used to deduplicate translation targets. This can be interpreted that changing the code inside expressions in your source code should not fail on future
extract
andbuild
calls but there seems to exist some validation that compares the value ofequiv-text
attribute.Reproduction
See linked discussion above for sample and error message.
Workaround
Manually update the xliff to match the
equiv-text
Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
@lit/localize-tools@0.7.1
Browser/OS/Node environment
n/a
The text was updated successfully, but these errors were encountered: