-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] XLIFF 2.0 read support #12853
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
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
add XliffVersion 2.0
- Loading branch information
commit 0971c65d89b57e2046ed8013954b3f95e03cf5ac
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/Symfony/Component/Translation/Loader/XliffVersion/XliffVersion20.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Translation\Loader\XliffVersion; | ||
|
||
use Symfony\Component\Translation\MessageCatalogue; | ||
|
||
/** | ||
* XliffVersion20 loads XLIFF files identified with version 2.0 | ||
* | ||
* @author Berny Cantos <be@rny.cc> | ||
*/ | ||
class XliffVersion20 extends AbstractXliffVersion | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getSchema() | ||
{ | ||
$source = file_get_contents(__DIR__.'/../schema/dic/xliff-core/xliff-core-2.0.xsd'); | ||
|
||
return $this->fixXmlLocation($source, 'informativeCopiesOf3rdPartySchemas/w3c/xml.xsd'); | ||
} | ||
|
||
/** | ||
* @param \DOMDocument $dom | ||
* @param MessageCatalogue $catalogue | ||
* @param string $domain | ||
*/ | ||
public function extract(\DOMDocument $dom, MessageCatalogue $catalogue, $domain) | ||
{ | ||
$xml = simplexml_import_dom($dom); | ||
$encoding = strtoupper($dom->encoding); | ||
|
||
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:2.0'); | ||
|
||
foreach ($xml->xpath('//xliff:unit/xliff:segment') as $segment) { | ||
$source = $segment->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) $segment->target, $encoding); | ||
|
||
$catalogue->set((string) $source, $target, $domain); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Symfony/Component/Translation/Tests/fixtures/resources-2.0.xlf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en-US" trgLang="ja-JP"> | ||
<file id="f1" original="Graphic Example.psd"> | ||
<skeleton href="Graphic Example.psd.skl"/> | ||
<unit id="1"> | ||
<segment> | ||
<source>Quetzal</source> | ||
<target>Quetzal</target> | ||
</segment> | ||
</unit> | ||
<group id="1"> | ||
<unit id="2"> | ||
<segment> | ||
<source>An application to manipulate and process XLIFF documents</source> | ||
<target>XLIFF 文書を編集、または処理 するアプリケーションです。</target> | ||
</segment> | ||
</unit> | ||
<unit id="3"> | ||
<segment> | ||
<source>XLIFF Data Manager</source> | ||
<target>XLIFF データ・マネージャ</target> | ||
</segment> | ||
</unit> | ||
</group> | ||
</file> | ||
</xliff> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You don't handle an
UnexpectedValueException
that might be thrown ingetVersionNumber()
neither here or in theload()
method.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.
Sure, my bad!
This should throw a
InvalidArgumentException
so we can catch onload
method for better message readability.Easy fix. Thank you!