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];
|
$ids = ['singular' => $singularId, 'plural' => $pluralId];
|
||||||
$item = compact('ids', 'translated');
|
$item = compact('ids', 'translated');
|
||||||
|
|
||||||
if (\is_array($item['translated'])) {
|
if (!empty($item['ids']['singular'])) {
|
||||||
$messages[$item['ids']['singular']] = stripcslashes($item['translated'][0]);
|
$id = $item['ids']['singular'];
|
||||||
if (isset($item['ids']['plural'])) {
|
if (isset($item['ids']['plural'])) {
|
||||||
$plurals = [];
|
$id .= '|'.$item['ids']['plural'];
|
||||||
foreach ($item['translated'] as $plural => $translated) {
|
|
||||||
$plurals[] = sprintf('{%d} %s', $plural, $translated);
|
|
||||||
}
|
|
||||||
$messages[$item['ids']['plural']] = stripcslashes(implode('|', $plurals));
|
|
||||||
}
|
}
|
||||||
} elseif (!empty($item['ids']['singular'])) {
|
$messages[$id] = stripcslashes(implode('|', (array) $item['translated']));
|
||||||
$messages[$item['ids']['singular']] = stripcslashes($item['translated']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,10 @@ class MoFileLoaderTest extends TestCase
|
|||||||
$resource = __DIR__.'/../fixtures/plurals.mo';
|
$resource = __DIR__.'/../fixtures/plurals.mo';
|
||||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
$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('en', $catalogue->getLocale());
|
||||||
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user