Skip to content

Commit

Permalink
Preserve translation ids that are numeric values
Browse files Browse the repository at this point in the history
Fix #83
  • Loading branch information
willdurand committed Jan 3, 2014
1 parent 0996839 commit 734a21c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getTranslationsAction(Request $request, $domain, $_format)
$catalogue = $this->loaders[$extension]
->load($file, $locale, $domain);

$translations[$locale][$domain] = array_merge_recursive(
$translations[$locale][$domain] = array_replace_recursive(
$translations[$locale][$domain],
$catalogue->all($domain)
);
Expand Down
2 changes: 1 addition & 1 deletion Dumper/TranslationDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private function getTranslations()
$catalogue = $this->loaders[$extension]
->load($file, $locale, $domain);

$translations[$locale][$domain] = array_merge_recursive(
$translations[$locale][$domain] = array_replace_recursive(
$translations[$locale][$domain],
$catalogue->all($domain)
);
Expand Down
18 changes: 18 additions & 0 deletions Tests/Controller/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,22 @@ public function testGetJsTranslationsWithUnknownLocale()
JS
, $response->getContent());
}

public function testGetTranslationsWithNumericKeys()
{
$client = static::createClient();

$crawler = $client->request('GET', '/translations/numerics.json?locales=en');
$response = $client->getResponse();

$this->assertEquals(<<<JSON
{
"fallback": "en",
"defaultDomain": "messages",
"translations": {"en":{"numerics":{"7":"Nos occasions","8":"Nous contacter","12":"pr\u00e9nom","13":"nom","14":"adresse","15":"code postal"}}}
}
JSON
, $response->getContent());
}
}
10 changes: 10 additions & 0 deletions Tests/Dumper/TranslationDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function testDump()
'messages/fr.json',
'foo/en.js',
'foo/en.json',
'numerics/en.js',
'numerics/en.json',
) as $file) {
$this->assertFileExists($this->target . '/translations/' . $file);
}
Expand Down Expand Up @@ -100,5 +102,13 @@ public function testDump()
JSON
, file_get_contents($this->target . '/translations/config.json'));

$this->assertEquals(<<<JSON
{
"translations": {"en":{"numerics":{"7":"Nos occasions","8":"Nous contacter","12":"pr\u00e9nom","13":"nom","14":"adresse","15":"code postal"}}}
}
JSON
, file_get_contents($this->target . '/translations/numerics/en.json'));
}
}
31 changes: 31 additions & 0 deletions Tests/Fixtures/app/Resources/translations/numerics.en.xliff
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>7</source>
<target>Nos occasions</target>
</trans-unit>
<trans-unit id="2">
<source>8</source>
<target>Nous contacter</target>
</trans-unit>
<trans-unit id="3">
<source>12</source>
<target>prénom</target>
</trans-unit>
<trans-unit id="4">
<source>13</source>
<target>nom</target>
</trans-unit>
<trans-unit id="5">
<source>14</source>
<target>adresse</target>
</trans-unit>
<trans-unit id="6">
<source>15</source>
<target>code postal</target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 734a21c

Please sign in to comment.