aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2011-09-13 01:46:00 +0200
committerOleg Pudeyev <oleg@bsdpower.com>2011-11-25 15:04:31 -0500
commitf16d72fcfb9a7621bf64b82cc2c710c6e484d965 (patch)
treefee4024018a61b725035017f7254e248cd229de8
parent757fcd3e63535f9fda68cf359f849a44059c7b27 (diff)
downloadforums-f16d72fcfb9a7621bf64b82cc2c710c6e484d965.tar
forums-f16d72fcfb9a7621bf64b82cc2c710c6e484d965.tar.gz
forums-f16d72fcfb9a7621bf64b82cc2c710c6e484d965.tar.bz2
forums-f16d72fcfb9a7621bf64b82cc2c710c6e484d965.tar.xz
forums-f16d72fcfb9a7621bf64b82cc2c710c6e484d965.zip
[ticket/10345] Fix documentation on the new function and the switch
Also do not min/max the value, but throw an error on an invalid Plural rule. PHPBB3-10345
-rw-r--r--phpBB/includes/session.php15
-rw-r--r--phpBB/language/en/common.php1
-rw-r--r--tests/user/lang_test.php4
3 files changed, 16 insertions, 4 deletions
diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php
index cd1975b9d3..4e5257506c 100644
--- a/phpBB/includes/session.php
+++ b/phpBB/includes/session.php
@@ -1901,6 +1901,10 @@ class user extends session
/**
* Determine which plural form we should use.
* For some languages this is not as simple as for English.
+ *
+ * @param $number int The number we want to get the plural case for
+ * @param $force_rule mixed False to use the plural rule of the language package
+ * or an integer to force a certain plural rule
*/
function get_plural_form($number, $force_rule = false)
{
@@ -1910,10 +1914,17 @@ class user extends session
return 0;
}
- // Default to english system
+ // Default to English system
$plural_rule = ($force_rule !== false) ? $force_rule : ((isset($this->lang['PLURAL_RULE'])) ? $this->lang['PLURAL_RULE'] : 1);
- $plural_rule = max(0, min($plural_rule, 15));
+ if ($plural_rule > 15 || $plural_rule < 0)
+ {
+ trigger_error('INVALID_PLURAL_RULE');
+ }
+ /**
+ * The following plural rules are based on a list published by the Mozilla Developer Network
+ * https://developer.mozilla.org/en/Localization_and_Plurals
+ */
switch ($plural_rule)
{
case 0:
diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php
index 57c9d916a2..cf01c6f32e 100644
--- a/phpBB/language/en/common.php
+++ b/phpBB/language/en/common.php
@@ -285,6 +285,7 @@ $lang = array_merge($lang, array(
'INTERESTS' => 'Interests',
'INVALID_DIGEST_CHALLENGE' => 'Invalid digest challenge.',
'INVALID_EMAIL_LOG' => '<strong>%s</strong> possibly an invalid e-mail address?',
+ 'INVALID_PLURAL_RULE' => 'The chosen plural rule is invalid. Valid values are integers between 0 and 15.',
'IP' => 'IP',
'IP_BLACKLISTED' => 'Your IP %1$s has been blocked because it is blacklisted. For details please see <a href="%2$s">%2$s</a>.',
diff --git a/tests/user/lang_test.php b/tests/user/lang_test.php
index 11e981bb7b..90b0cdfb0f 100644
--- a/tests/user/lang_test.php
+++ b/tests/user/lang_test.php
@@ -51,11 +51,11 @@ class phpbb_user_lang_test extends phpbb_test_case
$this->assertEquals($user->lang('ARRY', 2), '2 posts');
$this->assertEquals($user->lang('ARRY', 123), '123 posts');
- // Bug PHPBB3-9949
+ // ticket PHPBB3-9949
$this->assertEquals($user->lang('ARRY', 1, 2), '1 post');
$this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post');
- // Bug PHPBB3-10345
+ // ticket PHPBB3-10345
$user = new user;
$user->lang = array(
'PLURAL_RULE' => 13,