Forums / National / Russian / Зоопарк с окончаниями

Dayver
#7382 2009-02-09 06:51
Неее, в ленг файлы по умолчанию сунуть функции считаю категорически не правильным
Просто нуно функцию дорабатотать так (функции пагинации Трастмастер апгрейдил именно так):
/**
 * Function is intended for output of numerical results with the registration
 * declinations of words, for example: "1 answer", "2 answers" etc.
 */

function declension($digit,$expr,$onlyword=false)
{

	if(function_exists('declension_custom'))
	{
		// For custom declension functions in plugins or leng file
		return declension_custom($digit,$expr,$onlyword=false);
	}

    if(is_array($expr))
    {
            if(empty($expr[2])) $expr[2]=$expr[1];
            $i=preg_replace('/[^0-9]+/s','',$digit)%100;
            if($onlyword) $digit='';
            if($i>=5 && $i<=20) $res=$digit.' '.$expr[2];
            else
            {
                    $i%=10;
                    if($i==1) $res=$digit.' '.$expr[0];
                    elseif($i>=2 && $i<=4) $res=$digit.' '.$expr[1];
                    else $res=$digit.' '.$expr[2];
            }
    }
    else
    {
    $res = $digit.' '.$expr;
    }
 
        return trim($res);
}

Отличие в этом
....
	if(function_exists('declension_custom'))
	{
		// For custom declension functions in plugins or leng file
		return declension_custom($digit,$expr,$onlyword=false);
	}
....

И тогда саму функцию перерабатывать не придется и всем будет хорошо
Pavlo Tkachenko aka Dayver