-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Support omitting the <target> node in an .xlf file. #15604
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
Conversation
According to the XLIFF 1.2 specifications, the <target> node can be omitted: http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#trans-unit In the source language file, there is no need for a <target> node, because source and target are the same (provided that the translation key is stored in the "resname" attribute). The translator should fall back to the source string in this case, which this commit changes accordingly.
@@ -48,14 +48,14 @@ public function load($resource, $locale, $domain = 'messages') | |||
foreach ($xml->xpath('//xliff:trans-unit') as $translation) { | |||
$attributes = $translation->attributes(); | |||
|
|||
if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) { | |||
if (!(isset($attributes['resname']) || isset($translation->source))) { |
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 do we also skip when resname is not set? It's an optional attribute according to the specs (unrelated to this PR, was just wondering)
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.
We only continue if there is neither a resname attribute nor a source string, which is ok.
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.
Ah, now I understand. Shouldn't this then be changed to !isset($attributes['resname']) && !isset($translation->source)
? (which is a bit easier to read/understand)
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.
Of course this could be changed. We simply left it as it is to keep the PR as small as possible.
Depends on the reader which one is more easy to read 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.
@wouterj I also prefer your way of writing it :)
Anything that makes the XliffFileLoader actually loading Xliff instead of XML-mapped key/value pairs deserves a big 👍 :) |
👍 |
This PR should have been targeted towards version 2.3. Sorry for that. |
continue; | ||
} | ||
|
||
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source; | ||
// If the xlf file has another encoding specified, try to convert it because | ||
// simple_xml will always return utf-8 encoded values | ||
$target = $this->utf8ToCharset((string) $translation->target, $encoding); | ||
$target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $translation->source), $encoding); |
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.
Shouldn't you use $source
instead of $translation->source
? When the resname
attribute is set for instance.
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.
No, because if there is a "resname" attribute, it will contain a translation key such as author.name.not_blank
.
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.
Right, but then, IIUC, you need to take into account the possibility of $translation->source
not being set.
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 have updated the PR accordingly.
ping @symfony/deciders |
👍 |
@aitboudad Can you take care of merging it in 2.3 (resolving the conflict) and merging 2.3 into 2.7 atferwards? Thanks. |
@fabpot ok |
see #15611 |
…node in an .xlf file. (leofeyer) This PR was merged into the 2.3 branch. Discussion ---------- [Translation][Xliff Loader] Support omitting the <target> node in an .xlf file. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This is a cherry pick of #15604 on 2.3 Commits ------- 3dcda1a Support omitting the <target> node in an .xlf file.
…tboudad) This PR was merged into the 2.8 branch. Discussion ---------- [Translation][Xliff loader] fixed check target node. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | related to #15604 | License | MIT | Doc PR | ~ Commits ------- 09e88dc [Translation][Xliff loader] fixed check target node.
According to the XLIFF 1.2 specifications, the
<target>
node can be omitted:In the source language file, there is no need for a
<target>
node, because source and target are the same (provided that the translation key is stored in the "resname" attribute). The translator should fall back to the source string in this case, which this commit changes accordingly.