Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
wants to merge 2 commits into from
Closed

Support omitting the <target> node in an .xlf file. #15604

wants to merge 2 commits into from

Conversation

leofeyer
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

According to the XLIFF 1.2 specifications, the <target> node can be omitted:

Contents:
One <source> element, followed by
Zero or one <seg-source> element, followed by
Zero or one <target> element, followed by
Zero, one or more <context-group>, <count-group>, <prop-group>, <note>, <alt-trans> elements, in any order, followed by
Zero, one or more non-XLIFF elements.

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.

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))) {
Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Member

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)

Copy link
Contributor

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. ;)

Copy link
Contributor Author

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 :)

@wouterj
Copy link
Member

wouterj commented Aug 24, 2015

Anything that makes the XliffFileLoader actually loading Xliff instead of XML-mapped key/value pairs deserves a big 👍 :)

@fabpot
Copy link
Member

fabpot commented Aug 24, 2015

👍

@leofeyer
Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@fabpot
Copy link
Member

fabpot commented Aug 25, 2015

ping @symfony/deciders

@aitboudad
Copy link
Contributor

👍

@fabpot
Copy link
Member

fabpot commented Aug 25, 2015

@aitboudad Can you take care of merging it in 2.3 (resolving the conflict) and merging 2.3 into 2.7 atferwards? Thanks.

@aitboudad
Copy link
Contributor

@fabpot ok

@aitboudad
Copy link
Contributor

see #15611

@aitboudad aitboudad closed this Aug 25, 2015
aitboudad added a commit that referenced this pull request Aug 25, 2015
…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.
nicolas-grekas added a commit that referenced this pull request Aug 27, 2015
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants