Load plurals from mo files properly
This commit is contained in:
parent
2774705c39
commit
97d28b5e4e
@ -111,17 +111,12 @@ class MoFileLoader extends FileLoader
|
||||
$ids = ['singular' => $singularId, 'plural' => $pluralId];
|
||||
$item = compact('ids', 'translated');
|
||||
|
||||
if (\is_array($item['translated'])) {
|
||||
$messages[$item['ids']['singular']] = stripcslashes($item['translated'][0]);
|
||||
if (!empty($item['ids']['singular'])) {
|
||||
$id = $item['ids']['singular'];
|
||||
if (isset($item['ids']['plural'])) {
|
||||
$plurals = [];
|
||||
foreach ($item['translated'] as $plural => $translated) {
|
||||
$plurals[] = sprintf('{%d} %s', $plural, $translated);
|
||||
$id .= '|'.$item['ids']['plural'];
|
||||
}
|
||||
$messages[$item['ids']['plural']] = stripcslashes(implode('|', $plurals));
|
||||
}
|
||||
} elseif (!empty($item['ids']['singular'])) {
|
||||
$messages[$item['ids']['singular']] = stripcslashes($item['translated']);
|
||||
$messages[$id] = stripcslashes(implode('|', (array) $item['translated']));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,10 @@ class MoFileLoaderTest extends TestCase
|
||||
$resource = __DIR__.'/../fixtures/plurals.mo';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals(['foo' => 'bar', 'foos' => '{0} bar|{1} bars'], $catalogue->all('domain1'));
|
||||
$this->assertEquals([
|
||||
'foo|foos' => 'bar|bars',
|
||||
'{0} no foos|one foo|%count% foos' => '{0} no bars|one bar|%count% bars',
|
||||
], $catalogue->all('domain1'));
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||
}
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user