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
Add support for XLIFF placeholders #2364
Conversation
607f635
to
ab067ee
Compare
weblate/formats/ttkit.py
Outdated
@@ -37,7 +37,7 @@ | |||
|
|||
from weblate.formats.base import FileUnit, FileFormat | |||
|
|||
from weblate.trans.util import get_string, join_plural | |||
from weblate.trans.util import get_string, join_plural, string_to_rich, rich_to_string |
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.
Line too long (86 > 79 characters)
weblate/trans/util.py
Outdated
|
||
|
||
def string_to_rich(string): | ||
"""Transform a string containing XLIFF placeholders as XML into a rich content (StringElement)""" |
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.
Line too long (101 > 79 characters)
weblate/trans/util.py
Outdated
|
||
|
||
def rich_to_string(string_elements): | ||
"""Transform rich content (StringElement) into a string with placeholder kept as XML""" |
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.
Line too long (91 > 79 characters)
Thanks! Looks good generally, some remarks:
|
Most of the test failures are probably caused by this: File "/home/travis/build/WeblateOrg/weblate/weblate/formats/ttkit.py", line 75, in get_source
return rich_to_string(self.unit.rich_source)
File "/home/travis/build/WeblateOrg/weblate/weblate/trans/util.py", line 308, in rich_to_string
result += string_without_wrapping_element
TypeError: must be str, not bytes |
Codecov Report
@@ Coverage Diff @@
## master #2364 +/- ##
=========================================
+ Coverage 90.95% 92% +1.05%
=========================================
Files 396 394 -2
Lines 27590 27287 -303
Branches 3044 3027 -17
=========================================
+ Hits 25094 25105 +11
+ Misses 1662 1376 -286
+ Partials 834 806 -28
|
I fixed style and unit tests (hopefully) and added new tests to cover new code. Could you please have a second look ? |
Thanks, it looks better now. Still there is one failure on the xliff import:
|
4287828
to
b186022
Compare
Is this still WIP or it should be ready for review? Anyay it at least needs rebase on current code (I guess introduction of xliff states caused the conflicts). |
This should allow to translate units containing placeholders such as the one used by Angular i18n. PoXliff will not support placehoders, because it probably doesn't make sense to support XLIFF specific placeholders in a format that actually embed PO placeholders. Fixes WeblateOrg#490 Fixes WeblateOrg#1535 Signed-off-by: Adrien Crivelli <adrien.crivelli@gmail.com>
b186022
to
12252a9
Compare
@@ -415,6 +417,29 @@ class XliffUnit(TTKitUnit): | |||
'new', 'needs-translation', 'needs-adaptation', 'needs-l10n' | |||
)) | |||
|
|||
@cached_property |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
@@ -501,6 +526,19 @@ def mark_approved(self, value): | |||
if self.xliff_state: | |||
self.xliff_node.set('state', 'final' if value else 'translated') | |||
|
|||
class PoXliffUnit(XliffUnit): |
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.
Expected 2 blank lines, found 1
This is not a WIP anymore and should be reviewed for merge. I rebased and squashed on master. Let me know if that's ok. |
@@ -501,6 +526,19 @@ def mark_approved(self, value): | |||
if self.xliff_state: | |||
self.xliff_node.set('state', 'final' if value else 'translated') | |||
|
|||
class PoXliffUnit(XliffUnit): |
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'm not really sure this is needed. PoXliff is also used natively to get some of the gettext features to xliff, so disabling xliff placeholders might be not intended here.
Thanks, looks good, I'll merge this after releasing 3.3. I'd probably remove PoXliffUnit as that seems not wanted behavior to me. |
Merged, thanks for your contribution! |
My pleasure |
This is a work in progress and unit tests will be added and squashed when ready. But I wanted to double-check if I am going in the right direction before progressing further.
Given this XLIFF unit:
I store in DB the placeholder preserved as XML. So something like the following (after translation of target), note the absence of flags:
In Weblate, it will look like that:
Interestingly I did not implement any checks, but the placeholder are still highlighted. So I guess we don't need to do anything for that part ?
Does it look good to you ? should I keep going by fixing/adding unit tests ?
Fixes #490
Fixes #1535
Before submitting pull request, please ensure that: