Russian without Robotism, Part 1
I fully support the cleanliness and proper use of the Russian language. In life in general and in Runet in particular. For from inscriptions like "23 pieces" or the averaged versions of "23 pieces." mildly jarring.
Therefore, when the task arose to overcome roboticism in the endings of nouns, the corresponding function was developed and implemented (or rather, the plugin for Smarty).
The function is based on the rule - in total there are 3 options (sometimes fewer) noun endings for any Russian words used with numbers:
Naturally, having received this regularity, writing a code was not difficult.
After that, in the template it is enough to indicate the design of the form
Z.Y. Thank you for the correction to the account * 10- * 20
Therefore, when the task arose to overcome roboticism in the endings of nouns, the corresponding function was developed and implemented (or rather, the plugin for Smarty).
The function is based on the rule - in total there are 3 options (sometimes fewer) noun endings for any Russian words used with numbers:
- If the last digit of the number is 1 (but not 11)
- If the last digit of the number is 2,3,4 (but not * 12, * 13, * 14)
- All other cases.
Naturally, having received this regularity, writing a code was not difficult.
Copy Source | Copy HTML- /**
- * Smarty {number2word} function plugin
- *
- * Type: function* Name: number2word* Purpose: Get russian (or other lang) word equivalent to current number of items
- * @author Beresnev Sergey
- * @param array
- * @param Smarty
- */
- function smarty_function_number2word($params, &$smarty)
- {
- if (!isset($params['number'])) {
- $smarty->trigger_error("numbertoword: Отсутствует параметр 'number'");
- return;
- }
- if (!isset($params['name1']) or !isset($params['name2']) or !isset($params['name3'])) {
- $smarty->trigger_error("numbertoword: Отсутствуют параметры 'name1' или 'name2' или 'name3'");
- return;
- }
- $temp = strval($params['number']);
- $temp = $temp[utf8_strlen($temp)-1];
- return (($temp>1 and $temp <5 and (intval($params['number']%100)>19 or intval($params['number']%100)<10))?$params['name2']:($temp==1?$params['name1']:$params['name3']));
- }
After that, in the template it is enough to indicate the design of the form
{number2word number=$your_number name1=Строка name2=Строки name3=Строк}
Z.Y. Thank you for the correction to the account * 10- * 20