Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Russian #41

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/CronExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function getFields(): array
];
}

public function langCountable(string $type, int $number): array|string
public function langCountable(string $type, int $number, string $case = 'nominative'): array|string
{
$array = $this->translations[$type];

$value = $array[$number] ?? ($array['default'] ?: '');
$value = $array[$case][$number] ?? $array[$number] ?? $array[$case]['default'] ?? $array['default'] ?? '';

return str_replace(':number', $number, $value);
}
Expand All @@ -66,7 +66,7 @@ public function lang(string $key, array $replacements = [])

protected function ensureLocaleExists(string $fallbackLocale = 'en'): void
{
if (! is_dir($this->getTranslationDirectory())) {
if (!is_dir($this->getTranslationDirectory())) {
$this->locale = $fallbackLocale;
}
}
Expand All @@ -92,7 +92,7 @@ protected function loadTranslationFile(string $file)
{
$filename = sprintf('%s/%s.php', $this->getTranslationDirectory(), $file);

if (! is_file($filename)) {
if (!is_file($filename)) {
throw new TranslationFileMissingException($this->locale, $file);
}

Expand Down
8 changes: 4 additions & 4 deletions src/DaysOfMonthField.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ public function translateOnce(): ?string

if ($month->hasType('Every') && $month->dropped) {
return $this->lang('days_of_month.every_on_day', [
'day' => $this->format()
'day' => $this->format('dative'),
]);
}

return $this->lang('days_of_month.once_on_day', [
'day' => $this->format()
'day' => $this->format(),
]);
}

public function format(): string
public function format(string $case = 'nominative'): string
{
return $this->langCountable('ordinals', $this->getValue());
return $this->langCountable('ordinals', $this->getValue(), $case);
}
}
8 changes: 4 additions & 4 deletions src/DaysOfWeekField.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ public function translateMultiple(): string
*/
public function translateOnce(): ?string
{
if ($this->expression->day->hasType('Every') && ! $this->expression->day->dropped) {
if ($this->expression->day->hasType('Every') && !$this->expression->day->dropped) {
return null; // DaysOfMonthField adapts to "Every Sunday".
}

return $this->lang('days_of_week.once_on_day', [
'day' => $this->format()
'day' => $this->format('dative')
]);
}

/**
* @throws CronParsingException
*/
public function format(): string
public function format(string $case = 'nominative'): string
{
$weekday = $this->getValue() === 0 ? 7 : $this->getValue();

if ($weekday < 1 || $weekday > 7) {
throw new CronParsingException($this->expression->raw);
}

return $this->langCountable('days', $weekday);
return $this->langCountable('days', $weekday, $case);
}
}
4 changes: 2 additions & 2 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function getTimes(): array|string
return $this->langCountable('times', $this->getCount());
}

protected function langCountable(string $key, int $value): array|string
protected function langCountable(string $key, int $value, string $case = 'nominative'): array|string
{
return $this->expression->langCountable($key, $value);
return $this->expression->langCountable($key, $value, $case);
}

protected function lang(string $key, array $replacements = []): string
Expand Down
2 changes: 1 addition & 1 deletion src/HoursField.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function format(?MinutesField $minute = null): string
return $minute ? "{$hour}:{$minute->format()}" : "{$hour}:00";
}

$amOrPm = $this->getValue() < 12 ? 'am' : 'pm';
$amOrPm = $this->getValue() < 12 ? $this->lang('times.am') : $this->lang('times.pm');
$hour = $this->getValue() % 12;
$hour = $hour === 0 ? 12 : $hour;

Expand Down
8 changes: 4 additions & 4 deletions src/MonthsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ public function translateOnce(): string
if ($this->expression->day->hasType('Once')) {
return $this->lang('months.once_on_day', [
'month' => $this->format(),
'day' => $this->expression->day->format(),
'day' => $this->expression->day->format('dative'),
]);
}

return $this->lang('months.once_on_month', [
'month' => $this->format()
'month' => $this->format(),
]);
}

/**
* @throws CronParsingException
*/
public function format(): string
public function format(string $case = 'nominative'): string
{
if ($this->getValue() < 1 || $this->getValue() > 12) {
throw new CronParsingException($this->expression->raw);
}

return $this->langCountable('months', $this->getValue());
return $this->langCountable('months', $this->getValue(), $case);
}
}
4 changes: 4 additions & 0 deletions src/lang/ar/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'كل عام',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
4 changes: 4 additions & 0 deletions src/lang/de/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@
'years' => [
'every' => 'jedes Jahr',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
4 changes: 4 additions & 0 deletions src/lang/en/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'every year',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
4 changes: 4 additions & 0 deletions src/lang/es/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'cada año',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
4 changes: 4 additions & 0 deletions src/lang/fr/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'chaque année',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
4 changes: 4 additions & 0 deletions src/lang/hi/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'प्रत्येक वर्ष',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
4 changes: 4 additions & 0 deletions src/lang/lv/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'katru gadu',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
4 changes: 4 additions & 0 deletions src/lang/nl/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'elk jaar',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
]
];
4 changes: 4 additions & 0 deletions src/lang/pt/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'todos os anos',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
]
];
4 changes: 4 additions & 0 deletions src/lang/ro/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'în fiecare an',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
]
];
22 changes: 22 additions & 0 deletions src/lang/ru/days.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

return [
'nominative' => [
1 => 'в понедельник',
2 => 'во вторник',
3 => 'в среду',
4 => 'в четверг',
5 => 'в пятницу',
6 => 'в субботу',
7 => 'в воскресенье',
],
'dative' => [
1 => 'понедельникам',
2 => 'вторникам',
3 => 'средам',
4 => 'четвергам',
5 => 'пятницам',
6 => 'субботам',
7 => 'воскресеньям',
],
];
52 changes: 52 additions & 0 deletions src/lang/ru/fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

return [
'minutes' => [
'every' => 'каждую минуту',
'increment' => 'каждые :increment мин.',
'times_per_increment' => ':times каждые :increment мин.',
'multiple' => ':times в час',
],
'hours' => [
'every' => 'каждый час',
'once_an_hour' => 'раз в час',
'increment' => 'каждые :increment ч',
'multiple_per_increment' => ':count ч из :increment',
'times_per_increment' => ':times каждые :increment ч',
'increment_chained' => 'каждые :increment ч',
'multiple_per_day' => ':count ч в день',
'times_per_day' => ':times в день',
'once_at_time' => 'в :time',
],
'days_of_month' => [
'every' => 'каждый день',
'increment' => 'каждые :increment дн.',
'multiple_per_increment' => ':count дн. из :increment',
'multiple_per_month' => ':count дн. в месяц',
'once_on_day' => 'на :day число',
'every_on_day' => ':day числа каждого месяца',
],
'months' => [
'every' => 'каждый месяц',
'every_on_day' => ':day число каждого месяца',
'increment' => 'каждые :increment мec.',
'multiple_per_increment' => ':count мес. из :increment',
'multiple_per_year' => ':count мес. в год',
'once_on_month' => 'в :month',
'once_on_day' => 'в :month :day числа',
],
'days_of_week' => [
'every' => 'каждую неделю :weekday',
'increment' => 'Каждые :increment дни недели',
'multiple_per_increment' => ':count дн. недели из :increment',
'multiple_days_a_week' => ':count дн. в неделю',
'once_on_day' => 'по :day',
],
'years' => [
'every' => 'каждый год',
],
'times' => [
'am' => ' утра',
'pm' => ' вечера',
],
];
32 changes: 32 additions & 0 deletions src/lang/ru/months.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

return [
'nominative' => [
1 => 'январе',
2 => 'феврале',
3 => 'марте',
4 => 'апреле',
5 => 'мае',
6 => 'июне',
7 => 'июле',
8 => 'августе',
9 => 'сентябре',
10 => 'октябре',
11 => 'ноябре',
12 => 'декабре',
],
'dative' => [
1 => 'январям',
2 => 'февралям',
3 => 'мартам',
4 => 'апрелям',
5 => 'маям',
6 => 'июням',
7 => 'июлям',
8 => 'августам',
9 => 'сентябрям',
10 => 'октябрям',
11 => 'ноябрям',
12 => 'декабрям',
],
];
11 changes: 11 additions & 0 deletions src/lang/ru/ordinals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'nominative' => [
'default' => ':number-ое',
3 => ':number-е',
],
'dative' => [
'default' => ':number-го',
],
];
9 changes: 9 additions & 0 deletions src/lang/ru/times.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

return [
'default' => ':number раз',
1 => 'один раз',
2 => 'два раза',
3 => '3 раза',
4 => '4 раза',
];
4 changes: 4 additions & 0 deletions src/lang/sk/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'každý rok',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
4 changes: 4 additions & 0 deletions src/lang/vi/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => 'hằng năm',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
4 changes: 4 additions & 0 deletions src/lang/zh-TW/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => '每年',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
4 changes: 4 additions & 0 deletions src/lang/zh/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
'years' => [
'every' => '每年',
],
'times' => [
'am' => 'am',
'pm' => 'pm',
],
];
Loading