Skip to content

Commit

Permalink
fixed Russian relative time: day handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Tino Ehrich committed Jun 8, 2016
1 parent b1718d3 commit 28c3765
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 30 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ You can now run through the result and put it formatted into a drop-down field o

# Changelog

### 1.20.6
- fixed:
- Russian locale relative time: day handling

### 1.20.5
- fixed:
- missing immutable handling
Expand Down
102 changes: 72 additions & 30 deletions src/Locales/ru_RU.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,78 @@
// locale: Русский (Russia) (ru_RU)
// author: Oleg Bogdanov https://github.com/wormen

/**
* returns ending for plural form of word by number and array of variants (1, 4, 5)
* example variants for apples ['яблоко', 'яблока', 'яблок']
*/

/**
* @param int $number
* @param array $endingArray
*
* @return string
*/
$getNumEnding = function($number, array $endingArray)
{
$number = $number % 100;

if ($number >= 11 && $number <= 19)
{
return $endingArray[2];
}

$i = $number % 10;

switch ($i)
{
case (1):
$ending = $endingArray[0];
break;
case (2):
case (3):
case (4):
$ending = $endingArray[1];
break;
default:
$ending = $endingArray[2];
}

return $ending;
};

return array(
"months" => explode('_', 'Январь_Февраль_Март_Апрель_Май_Июнь_Июль_Август_Сентябрь_Октябрь_Ноябрь_Декабрь'),
"monthsShort" => explode('_', 'Янв_Фев_Мрт_Апр_Май_Июн_Июл_Авг_Сен_Окт_Нбр_Дек'),
"weekdays" => explode('_', 'Понедельник_Вторник_Среда_Четверг_Пятница_Суббота_Воскресенье'),
"weekdaysShort" => explode('_', 'Пн_Вт_Ср_Чт_Пт_Сб_Вс'),
"calendar" => array(
"sameDay" => '[Сегодня]',
"nextDay" => '[Завтра]',
"lastDay" => '[Вчера]',
"lastWeek" => '[Прошлой] l',
"sameElse" => 'l',
"withTime" => '[at] H:i',
"default" => 'd/m/Y',
'months' => explode('_', 'Январь_Февраль_Март_Апрель_Май_Июнь_Июль_Август_Сентябрь_Октябрь_Ноябрь_Декабрь'),
'monthsShort' => explode('_', 'Янв_Фев_Мрт_Апр_Май_Июн_Июл_Авг_Сен_Окт_Нбр_Дек'),
'weekdays' => explode('_', 'Понедельник_Вторник_Среда_Четверг_Пятница_Суббота_Воскресенье'),
'weekdaysShort' => explode('_', 'Пн_Вт_Ср_Чт_Пт_Сб_Вс'),
'calendar' => array(
'sameDay' => '[Сегодня]',
'nextDay' => '[Завтра]',
'lastDay' => '[Вчера]',
'lastWeek' => '[Прошлой] l',
'sameElse' => 'l',
'withTime' => '[at] H:i',
'default' => 'd/m/Y',
),
"relativeTime" => array(
"future" => 'в %s',
"past" => '%s назад',
"s" => 'несколько секунд',
"m" => 'минуту',
"mm" => '%d минут',
"h" => 'час',
"hh" => '%d часов',
"d" => 'день',
"dd" => '%d дней',
"M" => 'месяц',
"MM" => '%d месяцев',
"y" => 'год',
"yy" => '%d лет',
'relativeTime' => array(
'future' => 'в %s',
'past' => '%s назад',
's' => 'несколько секунд',
'm' => 'минуту',
'mm' => '%d минут',
'h' => 'час',
'hh' => '%d часов',
'd' => 'день',
'dd' => function ($number) use ($getNumEnding)
{
return $getNumEnding($number, array('%d день', '%d дня', '%d дней'));
},
'M' => 'месяц',
'MM' => '%d месяцев',
'y' => 'год',
'yy' => '%d лет',
),
"ordinal" => function ($number)
'ordinal' => function ($number)
{
$n = $number % 100;
$ends = array('ой', 'ый', 'ой', 'ий', 'ый', 'ый', 'ой', 'ой', 'ой', 'ый');
Expand All @@ -44,8 +86,8 @@

return $number . '[' . $ends[$number % 10] . ']';
},
"week" => array(
"dow" => 1, // Monday is the first day of the week.
"doy" => 4 // The week that contains Jan 4th is the first week of the year.
'week' => array(
'dow' => 1, // Monday is the first day of the week.
'doy' => 4 // The week that contains Jan 4th is the first week of the year.
),
);

0 comments on commit 28c3765

Please sign in to comment.