Skip to content

Commit bed6b52

Browse files
Ilanlidoclaude
andcommitted
CM-75116: Pluralize guardrails messages with gettext
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 51e97b4 commit bed6b52

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎cycode/cli/apps/ai_guardrails/scan/handlers.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import threading
1515
from collections.abc import Callable
1616
from dataclasses import dataclass
17+
from gettext import ngettext
1718
from typing import TYPE_CHECKING, Any, NamedTuple
1819

1920
import typer
@@ -138,7 +139,7 @@ def handle_before_submit_prompt(ctx: typer.Context, payload: AIHookPayload, poli
138139
block_reason = SECRETS_BLOCK_REASON_BY_EVENT_TYPE[AiHookEventType.PROMPT]
139140
if scan_outcome.verdict == GuardrailsMode.BLOCK:
140141
outcome = AIHookOutcome.BLOCKED
141-
secrets = 'secrets' if len(scan_outcome.shas) > 1 else 'secret'
142+
secrets = ngettext('secret', 'secrets', len(scan_outcome.shas))
142143
user_message = f'{scan_outcome.violation_summary}\nRemove the {secrets} and resend.'
143144
if scan_outcome.shas:
144145
user_message += f'\n{_false_positive_user_hint(scan_outcome.shas)}'

‎cycode/cli/apps/ai_guardrails/scan/utils.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import sys
1010
from collections import defaultdict
11+
from gettext import ngettext
1112
from pathlib import Path
1213
from typing import TYPE_CHECKING
1314

@@ -160,4 +161,5 @@ def _build_severity_line(local_scan_results: list['LocalScanResult']) -> str:
160161
count = severity_counts[severity]
161162
severity_parts.append(f'{emoji} {severity.upper()} - {count}')
162163

163-
return f'Cycode found {detections_count} violations: {" | ".join(severity_parts)}'
164+
violations = ngettext('violation', 'violations', detections_count)
165+
return f'Cycode found {detections_count} {violations}: {" | ".join(severity_parts)}'

‎tests/cli/commands/ai_guardrails/scan/test_handlers.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ def test_violation_summary_lists_findings_without_a_sha() -> None:
545545

546546
summary, shas = build_violation_summary([local_scan_result])
547547

548+
assert 'Cycode found 1 violation:' in summary
548549
assert ' - GitHub Token' in summary
549550
assert shas == ()
550551

0 commit comments

Comments
 (0)