8000 [Translation] Fix handling of null messages in `ArrayLoader` · symfony/symfony@4be2036 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4be2036

Browse files
rob006nicolas-grekas
authored andcommitted
[Translation] Fix handling of null messages in ArrayLoader
1 parent d61b959 commit 4be2036

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ private function flatten(array $messages): array
4646
foreach ($messages as $key => $value) {
4747
if (\is_array($value)) {
4848
foreach ($this->flatten($value) as $k => $v) {
49-
$result[$key.'.'.$k] = $v;
49+
if (null !== $v) {
50+
$result[$key.'.'.$k] = $v;
51+
}
5052
}
51-
} else {
53+
} elseif (null !== $value) {
5254
$result[$key] = $value;
5355
}
5456
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ public function testLoad()
3030
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
3131
}
3232

33+
public function testLoadNonStringMessages()
34+
{
35+
$loader = new YamlFileLoader();
36+
$resource = __DIR__.'/../fixtures/non-string.yml';
37+
$catalogue = $loader->load($resource, 'en', 'domain1');
38+
39+
$this->assertSame(['root.foo2' => '', 'root.bar' => 'bar'], $catalogue->all('domain1'));
40+
}
41+
3342
public function testLoadDoesNothingIfEmpty()
3443
{
3544
$loader = new YamlFileLoader();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root:
2+
foo1:
3+
foo2: ''
4+
bar: 'bar'

0 commit comments

Comments
 (0)
0