Skip to content

Commit

Permalink
Merge pull request #540 from goetas/approved-translations
Browse files Browse the repository at this point in the history
test translation state is preserved for xliff
  • Loading branch information
goetas authored Apr 21, 2020
2 parents b77674d + 745b3f2 commit a94d149
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function forThisFile($id, $domain = 'messages')
* @param string $id
* @param string $domain
*
* @return Message
* @return static
*
* @static
*/
Expand Down
14 changes: 14 additions & 0 deletions Tests/Translation/Loader/Symfony/xliff/workflow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" target-language="" datatype="plaintext" original="not.available" tool="JMSTranslationBundle">
<header>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
</header>
<body>
<trans-unit id="1" approved="yes">
<source>foo1</source>
<target state="needs-adaptation">bar</target>
</trans-unit>
</body>
</file>
</xliff>
19 changes: 19 additions & 0 deletions Tests/Translation/Loader/XliffLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace JMS\TranslationBundle\Tests\Translation\Loader;

use JMS\TranslationBundle\Model\Message\XliffMessage;
use JMS\TranslationBundle\Model\Message\XliffMessageState;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Dumper\XliffDumper;
use JMS\TranslationBundle\Translation\Loader\XliffLoader;
Expand Down Expand Up @@ -63,6 +64,24 @@ public function testLoadWithSymfonyFormat()
);
}

public function testWorkflowAttributes()
{
$loader = new XliffLoader();

$expected = new MessageCatalogue();
$expected->setLocale('en');
$expected->add(XliffMessage::create('foo1')
->setDesc('foo1')
->setLocaleString('bar')
->setState(XliffMessageState::STATE_NEEDS_ADAPTATION)
->setApproved(true));

$this->assertEquals(
$expected,
$loader->load(__DIR__ . '/Symfony/xliff/workflow.xml', 'en')
);
}

public function getTestFiles()
{
$files = [];
Expand Down
2 changes: 1 addition & 1 deletion Translation/Loader/XliffLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function load($resource, $locale, $domain = 'messages')
->setLocaleString((string) $trans->target);
\assert($m instanceof Message);

$m->setApproved($trans['approved']==='yes');
$m->setApproved((string) $trans['approved']==='yes');

if (isset($trans->target['state'])) {
$m->setState((string) $trans->target['state']);
Expand Down

0 comments on commit a94d149

Please sign in to comment.