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

This commit is contained in:
El RIDO 2016-12-25 11:37:45 +01:00
parent fc874fe448
commit ecd8a51137
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
10 changed files with 31 additions and 13 deletions

View File

@ -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.":

View File

@ -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

View File

@ -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

View File

@ -52,7 +52,7 @@ if ($MARKDOWN):
<?php
endif;
?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-aELW4Wl6uhX5AE217S7csrmyQ/CM3N2au0K307miNMI3oKmyax4s+KxX0BZJrf9Vr5U8SqKlFsa9rdQt1FDxJw==" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-V/iOsbg0tz5cbcOCtBOgY+uK/X92E8EQLlW6L7OYvzLSYOO1YfPVupEbYEWgOj9KllOLrIsN8Oe+MfBsnFSW2g==" crossorigin="anonymous"></script>
<!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]-->

View File

@ -52,7 +52,7 @@ if ($MARKDOWN):
<?php
endif;
?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-aELW4Wl6uhX5AE217S7csrmyQ/CM3N2au0K307miNMI3oKmyax4s+KxX0BZJrf9Vr5U8SqKlFsa9rdQt1FDxJw==" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-V/iOsbg0tz5cbcOCtBOgY+uK/X92E8EQLlW6L7OYvzLSYOO1YfPVupEbYEWgOj9KllOLrIsN8Oe+MfBsnFSW2g==" crossorigin="anonymous"></script>
<!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]-->

View File

@ -53,7 +53,7 @@ if ($MARKDOWN):
<?php
endif;
?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-aELW4Wl6uhX5AE217S7csrmyQ/CM3N2au0K307miNMI3oKmyax4s+KxX0BZJrf9Vr5U8SqKlFsa9rdQt1FDxJw==" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-V/iOsbg0tz5cbcOCtBOgY+uK/X92E8EQLlW6L7OYvzLSYOO1YfPVupEbYEWgOj9KllOLrIsN8Oe+MfBsnFSW2g==" crossorigin="anonymous"></script>
<!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]-->

View File

@ -52,7 +52,7 @@ if ($MARKDOWN):
<?php
endif;
?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-aELW4Wl6uhX5AE217S7csrmyQ/CM3N2au0K307miNMI3oKmyax4s+KxX0BZJrf9Vr5U8SqKlFsa9rdQt1FDxJw==" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-V/iOsbg0tz5cbcOCtBOgY+uK/X92E8EQLlW6L7OYvzLSYOO1YfPVupEbYEWgOj9KllOLrIsN8Oe+MfBsnFSW2g==" crossorigin="anonymous"></script>
<!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]-->

View File

@ -53,7 +53,7 @@ if ($MARKDOWN):
<?php
endif;
?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-aELW4Wl6uhX5AE217S7csrmyQ/CM3N2au0K307miNMI3oKmyax4s+KxX0BZJrf9Vr5U8SqKlFsa9rdQt1FDxJw==" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-V/iOsbg0tz5cbcOCtBOgY+uK/X92E8EQLlW6L7OYvzLSYOO1YfPVupEbYEWgOj9KllOLrIsN8Oe+MfBsnFSW2g==" crossorigin="anonymous"></script>
<!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]-->

View File

@ -47,7 +47,7 @@ if ($MARKDOWN):
<?php
endif;
?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-aELW4Wl6uhX5AE217S7csrmyQ/CM3N2au0K307miNMI3oKmyax4s+KxX0BZJrf9Vr5U8SqKlFsa9rdQt1FDxJw==" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-V/iOsbg0tz5cbcOCtBOgY+uK/X92E8EQLlW6L7OYvzLSYOO1YfPVupEbYEWgOj9KllOLrIsN8Oe+MfBsnFSW2g==" crossorigin="anonymous"></script>
<!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]-->

View File

@ -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()