Skip to content

Commit 034c247

Browse files
committed
bug symfony#15619 [Translation] Fix the string casting in the XliffFileLoader (stof)
This PR was merged into the 2.3 branch. Discussion ---------- [Translation] Fix the string casting in the XliffFileLoader | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a symfony#15611 broke the usage of Xliff translation files (and so all Symfony projects as they are used in core) because it stores SimpleXmlElement instances in the MessageCatalogue, which breaks when loading the cache: ``` PHP Fatal error: Call to undefined method SimpleXMLElement::__set_state() in .../app/cache/test/translations/catalogue.en.1cd7e874b24ab41081c7781e4161053bf515fc91.php on line 9 ``` this is how the cache looks like (truncated a lot of course): ```php $catalogue = new MessageCatalogue('en', array ( 'validators' => array ( 'This value should be false.' => SimpleXMLElement::__set_state(array( 0 => 'This value should be false.', )), ), )); ``` This is a critical bug in the 2.3 and 2.7 branches Commits ------- b856f62 [Translation] Fix the string casting in the XliffFileLoader
2 parents fed77a3 + b856f62 commit 034c247

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/Symfony/Component/Translation/Loader/XliffFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function load($resource, $locale, $domain = 'messages')
5353
}
5454

5555
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
56-
$target = (string) isset($translation->target) ? $translation->target : $source;
56+
$target = (string) (isset($translation->target) ? $translation->target : $source);
5757

5858
// If the xlf file has another encoding specified, try to convert it because
5959
// simple_xml will always return utf-8 encoded values

src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function testLoad()
2525
$this->assertEquals('en', $catalogue->getLocale());
2626
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
2727
$this->assertSame(array(), libxml_get_errors());
28+
$this->assertContainsOnly('string', $catalogue->all('domain1'));
2829
}
2930

3031
public function testLoadWithInternalErrorsEnabled()

0 commit comments

Comments
 (0)