Use symfony/translation for L10N plurals
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
de911f6e5c
commit
ed3b391e47
2
3rdparty
2
3rdparty
|
@ -1 +1 @@
|
||||||
Subproject commit 107e29e4c81d6b255abee5bc77fef3040df6ca07
|
Subproject commit b45407a256b6197db435d378f24fb42d499de051
|
|
@ -25,6 +25,7 @@ namespace OC\L10N;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\L10N\IFactory;
|
use OCP\L10N\IFactory;
|
||||||
use Punic\Calendar;
|
use Punic\Calendar;
|
||||||
|
use Symfony\Component\Translation\PluralizationRules;
|
||||||
|
|
||||||
class L10N implements IL10N {
|
class L10N implements IL10N {
|
||||||
|
|
||||||
|
@ -191,8 +192,12 @@ class L10N implements IL10N {
|
||||||
*/
|
*/
|
||||||
public function getPluralFormFunction() {
|
public function getPluralFormFunction() {
|
||||||
if (is_null($this->pluralFormFunction)) {
|
if (is_null($this->pluralFormFunction)) {
|
||||||
$this->pluralFormFunction = $this->factory->createPluralFunction($this->pluralFormString);
|
$lang = $this->getLanguageCode();
|
||||||
|
$this->pluralFormFunction = function($n) use ($lang) {
|
||||||
|
return PluralizationRules::get($n, $lang);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->pluralFormFunction;
|
return $this->pluralFormFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,13 +60,4 @@ interface IFactory {
|
||||||
* @since 9.0.0
|
* @since 9.0.0
|
||||||
*/
|
*/
|
||||||
public function languageExists($app, $lang);
|
public function languageExists($app, $lang);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a function from the plural string
|
|
||||||
*
|
|
||||||
* @param string $string
|
|
||||||
* @return string Unique function name
|
|
||||||
* @since 9.0.0
|
|
||||||
*/
|
|
||||||
public function createPluralFunction($string);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,33 +432,6 @@ class FactoryTest extends TestCase {
|
||||||
$this->assertSame($expected, $this->invokePrivate($factory, 'findL10nDir', [$app]));
|
$this->assertSame($expected, $this->invokePrivate($factory, 'findL10nDir', [$app]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataCreatePluralFunction() {
|
|
||||||
return [
|
|
||||||
['nplurals=2; plural=(n != 1);', 0, 1],
|
|
||||||
['nplurals=2; plural=(n != 1);', 1, 0],
|
|
||||||
['nplurals=2; plural=(n != 1);', 2, 1],
|
|
||||||
['nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;', 0, 2],
|
|
||||||
['nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;', 1, 0],
|
|
||||||
['nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;', 2, 1],
|
|
||||||
['nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;', 3, 1],
|
|
||||||
['nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;', 4, 1],
|
|
||||||
['nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;', 5, 2],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider dataCreatePluralFunction
|
|
||||||
*
|
|
||||||
* @param string $function
|
|
||||||
* @param int $count
|
|
||||||
* @param int $expected
|
|
||||||
*/
|
|
||||||
public function testCreatePluralFunction($function, $count, $expected) {
|
|
||||||
$factory = $this->getFactory();
|
|
||||||
$fn = $factory->createPluralFunction($function);
|
|
||||||
$this->assertEquals($expected, $fn($count));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dataFindLanguage() {
|
public function dataFindLanguage() {
|
||||||
return [
|
return [
|
||||||
// Not logged in
|
// Not logged in
|
||||||
|
|
Loading…
Reference in New Issue