From edf3ff5a53b353ed4a5d9d617bfd06a6c13b3bac Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 7 Aug 2016 11:52:49 +0200 Subject: [PATCH] Initialize a translation function It matches the API of ngettext(). --- application/Languages.php | 21 ++++++++++++++++++++ index.php | 1 + tests/LanguagesTest.php | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 application/Languages.php create mode 100644 tests/LanguagesTest.php diff --git a/application/Languages.php b/application/Languages.php new file mode 100644 index 0000000..c8b0a25 --- /dev/null +++ b/application/Languages.php @@ -0,0 +1,21 @@ + 1 ? $nText : $text; + return sprintf($actualForm, $nb); +} diff --git a/index.php b/index.php index f7a62c5..091ad70 100644 --- a/index.php +++ b/index.php @@ -53,6 +53,7 @@ require_once 'application/config/ConfigPlugin.php'; require_once 'application/FeedBuilder.php'; require_once 'application/FileUtils.php'; require_once 'application/HttpUtils.php'; +require_once 'application/Languages.php'; require_once 'application/LinkDB.php'; require_once 'application/LinkFilter.php'; require_once 'application/LinkUtils.php'; diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php new file mode 100644 index 0000000..79c136c --- /dev/null +++ b/tests/LanguagesTest.php @@ -0,0 +1,41 @@ +assertEquals($text, t($text)); + } + + /** + * Test t() with a non identified plural form. + */ + public function testTranslatePluralNotID() + { + $text = '%s sandwich'; + $nText = '%s sandwiches'; + $this->assertEquals('0 sandwich', t($text, $nText)); + $this->assertEquals('1 sandwich', t($text, $nText, 1)); + $this->assertEquals('2 sandwiches', t($text, $nText, 2)); + } + + /** + * Test t() with a non identified invalid plural form. + */ + public function testTranslatePluralNotIDInvalid() + { + $text = 'sandwich'; + $nText = 'sandwiches'; + $this->assertEquals('sandwich', t($text, $nText, 1)); + $this->assertEquals('sandwiches', t($text, $nText, 2)); + } +}