Skip to content

Commit

Permalink
[Translation] Fix handling of null messages in ArrayLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
rob006 authored and nicolas-grekas committed May 19, 2023
1 parent 9a40139 commit de237e5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Loader/ArrayLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ private function flatten(array $messages): array
foreach ($messages as $key => $value) {
if (\is_array($value)) {
foreach ($this->flatten($value) as $k => $v) {
$result[$key.'.'.$k] = $v;
if (null !== $v) {
$result[$key.'.'.$k] = $v;
}
}
} else {
} elseif (null !== $value) {
$result[$key] = $value;
}
}
Expand Down
9 changes: 9 additions & 0 deletions Tests/Loader/YamlFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public function testLoad()
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
}

public function testLoadNonStringMessages()
{
$loader = new YamlFileLoader();
$resource = __DIR__.'/../fixtures/non-string.yml';
$catalogue = $loader->load($resource, 'en', 'domain1');

$this->assertSame(['root.foo2' => '', 'root.bar' => 'bar'], $catalogue->all('domain1'));
}

public function testLoadDoesNothingIfEmpty()
{
$loader = new YamlFileLoader();
Expand Down
4 changes: 4 additions & 0 deletions Tests/fixtures/non-string.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root:
foo1:
foo2: ''
bar: 'bar'

0 comments on commit de237e5

Please sign in to comment.