From ecd8a51137c4b9d0d221dab4798143f6d0291164 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 25 Dec 2016 11:37:45 +0100 Subject: [PATCH] writing a unit test for #145 lead to the discovery of two errors in the polish translations: error in formula and missing number placeholders in the translation strings --- i18n/pl.json | 8 ++++---- js/privatebin.js | 2 +- lib/I18n.php | 2 +- tpl/bootstrap-compact.php | 2 +- tpl/bootstrap-dark-page.php | 2 +- tpl/bootstrap-dark.php | 2 +- tpl/bootstrap-page.php | 2 +- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- tst/I18nTest.php | 20 +++++++++++++++++++- 10 files changed, 31 insertions(+), 13 deletions(-) diff --git a/i18n/pl.json b/i18n/pl.json index b5fce72..8c34f60 100644 --- a/i18n/pl.json +++ b/i18n/pl.json @@ -59,11 +59,11 @@ "Przełącz nawigację", "%d seconds": ["%d second", "%d second", "%d second"], "%d minutes": ["%d minut", "%d minut", "%d minut"], - "%d hours": ["%d godzina", "%d godzina", "godzinę"], + "%d hours": ["%d godzina", "%d godzina", "%d godzinę"], "%d days": ["%d dzień", "%d dzień", "%d dzień"], - "%d weeks": ["%d tydzień", "%d tydzień", "tydzień"], - "%d months": ["%d miesiąc", "%d miesiąc", "miesiąc"], - "%d years": ["%d rok", "%d rok", "rok"], + "%d weeks": ["%d tydzień", "%d tydzień", "%d tydzień"], + "%d months": ["%d miesiąc", "%d miesiąc", "%d miesiąc"], + "%d years": ["%d rok", "%d rok", "%d rok"], "Never": "nigdy", "Note: This is a test service: Data may be deleted anytime. Kittens will die if you abuse this service.": diff --git a/js/privatebin.js b/js/privatebin.js index 0186ae7..9971fcb 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -413,7 +413,7 @@ $(function() { case 'zh': return (n > 1 ? 1 : 0); case 'pl': - return (n === 1 ? 0 : n%10 >= 2 && n %10 <=4 && (n%100 < 10 || n%100 >= 20) ? 1 : 2); + return (n === 1 ? 0 : (n%10 >= 2 && n %10 <=4 && (n%100 < 10 || n%100 >= 20) ? 1 : 2)); case 'ru': return (n % 10 === 1 && n % 100 !== 11 ? 0 : (n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2)); // en, de diff --git a/lib/I18n.php b/lib/I18n.php index 2e1512a..d60f109 100644 --- a/lib/I18n.php +++ b/lib/I18n.php @@ -298,7 +298,7 @@ class I18n case 'zh': return $n > 1 ? 1 : 0; case 'pl': - return $n == 1 ? 0 : $n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2; + return $n == 1 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); case 'ru': return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); // en, de diff --git a/tpl/bootstrap-compact.php b/tpl/bootstrap-compact.php index e534df5..04afad3 100644 --- a/tpl/bootstrap-compact.php +++ b/tpl/bootstrap-compact.php @@ -52,7 +52,7 @@ if ($MARKDOWN): - + diff --git a/tpl/bootstrap-dark-page.php b/tpl/bootstrap-dark-page.php index db54946..fc86d65 100644 --- a/tpl/bootstrap-dark-page.php +++ b/tpl/bootstrap-dark-page.php @@ -52,7 +52,7 @@ if ($MARKDOWN): - + diff --git a/tpl/bootstrap-dark.php b/tpl/bootstrap-dark.php index f706034..0036e2b 100644 --- a/tpl/bootstrap-dark.php +++ b/tpl/bootstrap-dark.php @@ -53,7 +53,7 @@ if ($MARKDOWN): - + diff --git a/tpl/bootstrap-page.php b/tpl/bootstrap-page.php index f48284d..9e38b2c 100644 --- a/tpl/bootstrap-page.php +++ b/tpl/bootstrap-page.php @@ -52,7 +52,7 @@ if ($MARKDOWN): - + diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 6a6311c..dea9d01 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -53,7 +53,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 54d82b9..f98abe5 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + diff --git a/tst/I18nTest.php b/tst/I18nTest.php index f2f4ead..c4bc51a 100644 --- a/tst/I18nTest.php +++ b/tst/I18nTest.php @@ -63,7 +63,25 @@ class I18nTest extends PHPUnit_Framework_TestCase $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'pl;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2'; I18n::loadTranslations(); $this->assertEquals('pl', I18n::_('en'), 'browser language pl'); - $this->assertEquals('2 godzina', I18n::_('%d hours', 2), 'hours in polish'); + $this->assertEquals('1 godzina', I18n::_('%d hours', 1), '1 hour in polish'); + $this->assertEquals('2 godzina', I18n::_('%d hours', 2), '2 hours in polish'); + $this->assertEquals('12 godzinę', I18n::_('%d hours', 12), '12 hours in polish'); + $this->assertEquals('22 godzina', I18n::_('%d hours', 22), '22 hours in polish'); + $this->assertEquals('1 minut', I18n::_('%d minutes', 1), '1 minute in polish'); + $this->assertEquals('3 minut', I18n::_('%d minutes', 3), '3 minutes in polish'); + $this->assertEquals('13 minut', I18n::_('%d minutes', 13), '13 minutes in polish'); + $this->assertEquals('23 minut', I18n::_('%d minutes', 23), '23 minutes in polish'); + } + + public function testBrowserLanguageRuDetection() + { + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'ru;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2'; + I18n::loadTranslations(); + $this->assertEquals('ru', I18n::_('en'), 'browser language ru'); + $this->assertEquals('1 минуту', I18n::_('%d minutes', 1), '1 minute in russian'); + $this->assertEquals('3 минуты', I18n::_('%d minutes', 3), '3 minutes in russian'); + $this->assertEquals('10 минут', I18n::_('%d minutes', 10), '10 minutes in russian'); + $this->assertEquals('21 минуту', I18n::_('%d minutes', 21), '21 minutes in russian'); } public function testBrowserLanguageAnyDetection()