mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[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:
parent
757fcd3e63
commit
f16d72fcfb
3 changed files with 16 additions and 4 deletions
|
@ -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:
|
||||
|
|
|
@ -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>.',
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue