[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
This commit is contained in:
Joas Schilling 2011-09-13 01:46:00 +02:00 committed by Oleg Pudeyev
parent 757fcd3e63
commit f16d72fcfb
3 changed files with 16 additions and 4 deletions

View file

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

View file

@ -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>.',

View file

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