summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-08-07 15:50:00 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2017-08-07 19:53:36 +0200
commited3b391e4799bf1b4a4c2f990020f1069d46d3ac (patch)
tree2207a3963341d3ec4064453820b2304d13c588da
parentde911f6e5c394fc86f45edc58850fd2e7649913c (diff)
downloadnextcloud-server-ed3b391e4799bf1b4a4c2f990020f1069d46d3ac.tar.gz
nextcloud-server-ed3b391e4799bf1b4a4c2f990020f1069d46d3ac.zip
Use symfony/translation for L10N plurals
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
m---------3rdparty0
-rw-r--r--lib/private/L10N/L10N.php7
-rw-r--r--lib/public/L10N/IFactory.php9
-rw-r--r--tests/lib/L10N/FactoryTest.php27
4 files changed, 6 insertions, 37 deletions
diff --git a/3rdparty b/3rdparty
-Subproject 107e29e4c81d6b255abee5bc77fef3040df6ca0
+Subproject b45407a256b6197db435d378f24fb42d499de05
diff --git a/lib/private/L10N/L10N.php b/lib/private/L10N/L10N.php
index b933048982f..620c99dd1ec 100644
--- a/lib/private/L10N/L10N.php
+++ b/lib/private/L10N/L10N.php
@@ -25,6 +25,7 @@ namespace OC\L10N;
use OCP\IL10N;
use OCP\L10N\IFactory;
use Punic\Calendar;
+use Symfony\Component\Translation\PluralizationRules;
class L10N implements IL10N {
@@ -191,8 +192,12 @@ class L10N implements IL10N {
*/
public function getPluralFormFunction() {
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;
}
diff --git a/lib/public/L10N/IFactory.php b/lib/public/L10N/IFactory.php
index b5f93c2389c..9820082c72e 100644
--- a/lib/public/L10N/IFactory.php
+++ b/lib/public/L10N/IFactory.php
@@ -60,13 +60,4 @@ interface IFactory {
* @since 9.0.0
*/
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);
}
diff --git a/tests/lib/L10N/FactoryTest.php b/tests/lib/L10N/FactoryTest.php
index 77a56b5f945..171be67d336 100644
--- a/tests/lib/L10N/FactoryTest.php
+++ b/tests/lib/L10N/FactoryTest.php
@@ -432,33 +432,6 @@ class FactoryTest extends TestCase {
$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() {
return [
// Not logged in