Habr
All streams
Search
Write a publication
Settings
Login
Pull to refresh
0
0
digi
@digi
User
Follow
Send message
Profile
Articles
Posts
News
Comments
23
More
Dropdown
Bookmarks
81
Followers
Following
Copy RSS link
Множественные числа
digi
Oct 31 2007 at 15:18
Правильный набор условий:
if ($number % 100 > 10 && $number % 100 < 20) return $base . $e0;
if ($number % 10 == 1) return $base . $e1;
if ($number % 10 >= 2 && $number % 10 <= 4) return $base . $e2;
return $base . $e0;
Множественные числа
digi
Oct 31 2007 at 15:09
Буквально сегодня ночью для этих целей написал небольшую функцию Smarty.
Использование:
{ending number=$reviews base="реценз" e0='ий' e1='ия' e2='ии'}
{ending number=$comments base="комментар" e0='иев' e1='ий' e2='ия'}
И сама функция (файл /smarty/libs/plugins/function.ending.php):
function smarty_function_ending($params, &$smarty)
{
// ...
// проверки входных параметров пропущены
// ...
$base = !isset($params['base']) ? '' : $params['base']:
$e0 = $params['e0'];
$e1 = $params['e1'];
$e2 = $params['e2'];
$number = $params['number'];
if ($number % 10 == 1) return $base . $e1;
if ($number % 10 >= 2 && $number % 10 <= 4) return $base . $e2;
return $base . $e0;
}
</code>
«Выгуглен»: Кори Доктороу о всепроникающем Гугле
digi
Oct 24 2007 at 14:43
Да, Big Google is watching you.
Back
Here
1
2
There
Back
Information
Rating
Does not participate
Location
Украина
Date of birth
May 4 1979
Registered
September 28 2007
Activity
April 20 2015 at 07:31
if ($number % 100 > 10 && $number % 100 < 20) return $base . $e0;
if ($number % 10 == 1) return $base . $e1;
if ($number % 10 >= 2 && $number % 10 <= 4) return $base . $e2;
return $base . $e0;
Использование:
{ending number=$reviews base="реценз" e0='ий' e1='ия' e2='ии'}
{ending number=$comments base="комментар" e0='иев' e1='ий' e2='ия'}
И сама функция (файл /smarty/libs/plugins/function.ending.php):
function smarty_function_ending($params, &$smarty)
{
// ...
// проверки входных параметров пропущены
// ...
$base = !isset($params['base']) ? '' : $params['base']:
$e0 = $params['e0'];
$e1 = $params['e1'];
$e2 = $params['e2'];
$number = $params['number'];
if ($number % 10 == 1) return $base . $e1;
if ($number % 10 >= 2 && $number % 10 <= 4) return $base . $e2;
return $base . $e0;
}
</code>