[Translation] Added unescaping of ids in PoFileLoader
This commit is contained in:
parent
3b2bff89a4
commit
816a4a9ff1
@ -157,7 +157,7 @@ class PoFileLoader extends ArrayLoader implements LoaderInterface
|
||||
private function addMessage(array &$messages, array $item)
|
||||
{
|
||||
if (is_array($item['translated'])) {
|
||||
$messages[$item['ids']['singular']] = stripcslashes($item['translated'][0]);
|
||||
$messages[stripcslashes($item['ids']['singular'])] = stripcslashes($item['translated'][0]);
|
||||
if (isset($item['ids']['plural'])) {
|
||||
$plurals = $item['translated'];
|
||||
// PO are by definition indexed so sort by index.
|
||||
@ -169,10 +169,10 @@ class PoFileLoader extends ArrayLoader implements LoaderInterface
|
||||
$empties = array_fill(0, $count+1, '-');
|
||||
$plurals += $empties;
|
||||
ksort($plurals);
|
||||
$messages[$item['ids']['plural']] = stripcslashes(implode('|', $plurals));
|
||||
$messages[stripcslashes($item['ids']['plural'])] = stripcslashes(implode('|', $plurals));
|
||||
}
|
||||
} elseif (!empty($item['ids']['singular'])) {
|
||||
$messages[$item['ids']['singular']] = stripcslashes($item['translated']);
|
||||
$messages[stripcslashes($item['ids']['singular'])] = stripcslashes($item['translated']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,4 +76,28 @@ class PoFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
}
|
||||
|
||||
public function testEscapedId()
|
||||
{
|
||||
$loader = new PoFileLoader();
|
||||
$resource = __DIR__.'/../fixtures/escaped-id.po';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$messages = $catalogue->all('domain1');
|
||||
$this->assertArrayHasKey('escaped "foo"', $messages);
|
||||
$this->assertEquals('escaped "bar"', $messages['escaped "foo"']);
|
||||
}
|
||||
|
||||
public function testEscapedIdPlurals()
|
||||
{
|
||||
$loader = new PoFileLoader();
|
||||
$resource = __DIR__.'/../fixtures/escaped-id-plurals.po';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$messages = $catalogue->all('domain1');
|
||||
$this->assertArrayHasKey('escaped "foo"', $messages);
|
||||
$this->assertArrayHasKey('escaped "foos"', $messages);
|
||||
$this->assertEquals('escaped "bar"', $messages['escaped "foo"']);
|
||||
$this->assertEquals('escaped "bar"|escaped "bars"', $messages['escaped "foos"']);
|
||||
}
|
||||
}
|
||||
|
10
src/Symfony/Component/Translation/Tests/fixtures/escaped-id-plurals.po
vendored
Normal file
10
src/Symfony/Component/Translation/Tests/fixtures/escaped-id-plurals.po
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Language: en\n"
|
||||
|
||||
msgid "escaped \"foo\""
|
||||
msgid_plural "escaped \"foos\""
|
||||
msgstr[0] "escaped \"bar\""
|
||||
msgstr[1] "escaped \"bars\""
|
8
src/Symfony/Component/Translation/Tests/fixtures/escaped-id.po
vendored
Normal file
8
src/Symfony/Component/Translation/Tests/fixtures/escaped-id.po
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Language: en\n"
|
||||
|
||||
msgid "escaped \"foo\""
|
||||
msgstr "escaped \"bar\""
|
Reference in New Issue
Block a user