fix: decline inspection counts in Russian
This commit is contained in:
1 parent
b1b1c6bcf0
commit
a22d23dcd7
2 files changed
+22
-5
No files matched your search
+17
-5
@@ -52,6 +52,22 @@ def _points_phrase(value: float | int) -> str:
|
||||
return f"{number} {word}"
|
||||
|
||||
|
||||
def _times_phrase(value: int) -> str:
|
||||
"""Формирует правильную форму слова «раз» для количества осмотров."""
|
||||
integer = abs(int(value))
|
||||
last_two = integer % 100
|
||||
last = integer % 10
|
||||
if last_two == 1:
|
||||
word = "раз"
|
||||
elif 2 <= last_two <= 4:
|
||||
word = "раза"
|
||||
elif last in (2, 3, 4) and not 11 <= last_two <= 14:
|
||||
word = "раза"
|
||||
else:
|
||||
word = "раз"
|
||||
return f"{value} {word}"
|
||||
|
||||
|
||||
def render_coaching(session: CoachingSession, result: CoachingResult) -> str:
|
||||
"""
|
||||
Формирует итоговый текст отчёта за ЛУ/ЗУ-сессию.
|
||||
@@ -108,13 +124,9 @@ def render_inspection(report: InspectionReport, result: InspectionResult | None
|
||||
Если ресурсов нет — выводит "0" вместо списка.
|
||||
"""
|
||||
result = result or calculate_inspection(report)
|
||||
if report.inspections == 1:
|
||||
word = "раз"
|
||||
else:
|
||||
word = "раз"
|
||||
lines = [
|
||||
"#осмотр",
|
||||
f"{report.character_name} [{report.character_id}] осмотрел(-а) {report.place} {report.inspections} {word}."
|
||||
f"{report.character_name} [{report.character_id}] осмотрел(-а) {report.place} {_times_phrase(report.inspections)}."
|
||||
]
|
||||
if report.resources:
|
||||
lines.extend(
|
||||
|
||||
@@ -192,6 +192,11 @@ class ReportTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(calculate_inspection(report).points, 18)
|
||||
|
||||
def test_inspection_count_uses_correct_russian_form(self):
|
||||
for count, phrase in ((1, "1 раз"), (2, "2 раза"), (4, "4 раза"), (5, "5 раз"), (21, "21 раз"), (24, "24 раза")):
|
||||
report = InspectionReport("Белка", 1, "дупло", count)
|
||||
self.assertIn(phrase, render_inspection(report))
|
||||
|
||||
def test_inspection_points_include_attempts_and_resource_values(self):
|
||||
report = InspectionReport(
|
||||
character_name="Дикая Вишня", character_id=1604614,
|
||||
|
||||
Reference in new issue
Block a user