mirror of https://github.com/avecms/AVE.cms.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.4 KiB
96 lines
2.4 KiB
7 years ago
|
<?php
|
||
|
/**
|
||
|
* Smarty plugin - declension modifier
|
||
|
* @package Smarty
|
||
|
* @subpackage plugins
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* Модификатор declension: склонение существительных по правилам английского языка
|
||
|
*
|
||
|
* @param array $forms (напр: 0 => article, 1 => articles)
|
||
|
* @param int $count
|
||
|
* @return string
|
||
|
*/
|
||
|
function smarty_modifier_declension_en($forms, $count)
|
||
|
{
|
||
|
if ($count==1)
|
||
|
return $forms[0];
|
||
|
else
|
||
|
return $forms[1];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Модификатор declension: склонение существительных по правилам русского языка
|
||
|
*
|
||
|
* @param array $forms (напр: 0 => пень, 1 => пня, 2 => пней)
|
||
|
* @param int $count
|
||
|
* @return string
|
||
|
*/
|
||
|
function smarty_modifier_declension_ru($forms, $count)
|
||
|
{
|
||
|
$mod100 = $count % 100;
|
||
|
if (fmod($count, 1) != 0) return $forms[2];
|
||
|
switch ($count%10) {
|
||
|
case 1:
|
||
|
if ($mod100 == 11)
|
||
|
return $forms[2];
|
||
|
else
|
||
|
return $forms[0];
|
||
|
case 2:
|
||
|
case 3:
|
||
|
case 4:
|
||
|
if (($mod100 > 10) && ($mod100 < 20))
|
||
|
return $forms[2];
|
||
|
else
|
||
|
return $forms[1];
|
||
|
case 5:
|
||
|
case 6:
|
||
|
case 7:
|
||
|
case 8:
|
||
|
case 9:
|
||
|
case 0:
|
||
|
return $forms[2];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Модификатор declension: склонение существительных
|
||
|
*
|
||
|
* @param int $count
|
||
|
* @param string $forms
|
||
|
* @param string $language
|
||
|
* @return string
|
||
|
*/
|
||
|
function smarty_modifier_declension($count, $forms, $language='')
|
||
|
{
|
||
|
global $currentLanguage, $Language;
|
||
|
if (!$language)
|
||
|
$language = $currentLanguage;
|
||
|
|
||
|
$count = abs((int)$count);
|
||
|
|
||
|
// Пытаемся выщемить термин из словаря
|
||
|
if (preg_match('/^(.*)\/(.*)$/', $forms, $termine))
|
||
|
{
|
||
|
if ($termine[1] && $termine[2])
|
||
|
{
|
||
|
$forms = $Language[$termine[1]][$termine[2]];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Выделяем отдельные словоформы
|
||
|
$forms = explode(';', $forms);
|
||
|
return smarty_modifier_declension_ru($forms, $count);
|
||
|
|
||
|
/* $fn = 'smarty_modifier_declension_'.$language;
|
||
|
if (function_exists($fn))
|
||
|
{
|
||
|
// Есть персональная функция для текущего языка
|
||
|
return $fn($forms, $count);
|
||
|
} else {
|
||
|
// Действуем по образу и подобию английского языка
|
||
|
return smarty_modifier_declension_en($forms, $count);
|
||
|
}*/
|
||
|
}
|
||
|
?>
|