-
Notifications
You must be signed in to change notification settings - Fork 26.6k
fix(localize): translation file parser selection #35793
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
fix(localize): translation file parser selection #35793
Conversation
e7131b9
to
9dcc985
Compare
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.
LGTM, But I am not sure if I am the best person to review, as I am not familiar with the codebase. I did not see anything which would jump out at me.
...rc/tools/test/translate/translation_files/translation_parsers/xtb_translation_parser_spec.ts
Outdated
Show resolved
Hide resolved
...tools/test/translate/translation_files/translation_parsers/xliff1_translation_parser_spec.ts
Outdated
Show resolved
Hide resolved
...localize/src/tools/src/translate/translation_files/translation_parsers/translation_parser.ts
Show resolved
Hide resolved
d5af5ed
to
950ec6b
Compare
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.
LGTM, thanks @petebacondarwin! 👍
@petebacondarwin quick question: when can we remove deprecated APIs (after the corresponding release on CLI side)? Could you please create a ticket on that, so that we clean them up when possible? Thank you. |
@AndrewKushnir - regarding the deprecated overload. Since this is not actually a public API it does not have to follow our official deprecation rules. I just added the deprecation tag to remind the CLI to change their implementation. Once they have done so, we should be able to safely remove this overload. Tracking at FW-1979 |
This modifies the internal (but shared with CLI) API for loading/parsing translation files. Now the parsers will return a new `Diagnostics` object along with any translations and locale extracted from the file. It is up to the caller to decide what to do about this, if there are errors it is suggested that an error is thrown, which is what the `TranslationLoader` class does.
This enables complex work to be done in `TranslationParser.canParse()` without duplicating the work in `TranslationParser.parse()`.
…files Previously, the `Xliff1TranslationParser` only matched files that had a narrow choice of extensions (e.g. `xlf`) and also relied upon a regular expression match of an optional XML namespace directive. This commit relaxes the requirement on both of these and, instead, relies upon parsing the file into XML and identifying an element of the form `<xliff version="1.2">` which is the minimal requirement for such files.
…files Previously, the `Xliff2TranslationParser` only matched files that had a narrow choice of extensions (e.g. `xlf`) and also relied upon a regular expression match of an optional XML namespace directive. This commit relaxes the requirement on both of these and, instead, relies upon parsing the file into XML and identifying an element of the form `<xliff version="2.0">` which is the minimal requirement for such files.
This commit improves the `canParse()` method to check that the file is valid XML and has the expected root node. Previously it was relying upon a regular expression to do this.
950ec6b
to
4f2df99
Compare
…5793) This modifies the internal (but shared with CLI) API for loading/parsing translation files. Now the parsers will return a new `Diagnostics` object along with any translations and locale extracted from the file. It is up to the caller to decide what to do about this, if there are errors it is suggested that an error is thrown, which is what the `TranslationLoader` class does. PR Close #35793
This enables complex work to be done in `TranslationParser.canParse()` without duplicating the work in `TranslationParser.parse()`. PR Close #35793
…files (#35793) Previously, the `Xliff1TranslationParser` only matched files that had a narrow choice of extensions (e.g. `xlf`) and also relied upon a regular expression match of an optional XML namespace directive. This commit relaxes the requirement on both of these and, instead, relies upon parsing the file into XML and identifying an element of the form `<xliff version="1.2">` which is the minimal requirement for such files. PR Close #35793
…files (#35793) Previously, the `Xliff2TranslationParser` only matched files that had a narrow choice of extensions (e.g. `xlf`) and also relied upon a regular expression match of an optional XML namespace directive. This commit relaxes the requirement on both of these and, instead, relies upon parsing the file into XML and identifying an element of the form `<xliff version="2.0">` which is the minimal requirement for such files. PR Close #35793
This enables complex work to be done in `TranslationParser.canParse()` without duplicating the work in `TranslationParser.parse()`. PR Close #35793
…files (#35793) Previously, the `Xliff1TranslationParser` only matched files that had a narrow choice of extensions (e.g. `xlf`) and also relied upon a regular expression match of an optional XML namespace directive. This commit relaxes the requirement on both of these and, instead, relies upon parsing the file into XML and identifying an element of the form `<xliff version="1.2">` which is the minimal requirement for such files. PR Close #35793
…files (#35793) Previously, the `Xliff2TranslationParser` only matched files that had a narrow choice of extensions (e.g. `xlf`) and also relied upon a regular expression match of an optional XML namespace directive. This commit relaxes the requirement on both of these and, instead, relies upon parsing the file into XML and identifying an element of the form `<xliff version="2.0">` which is the minimal requirement for such files. PR Close #35793
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. |
These changes should fix #35525, and should be compatible with current CLI integration code (@clydin to confirm), although the
hint
based approach with accompanied change to remove the need to passdiagnostics
to constructors should also improve the performance and maintainability.This should be completely backward compatible with previous versions.
FW-1888