Skip to content

Commit 7fae7b1

Browse files
author
TJ Webb
committed
fix: initialize locale before agent messages
1 parent 9a1a239 commit 7fae7b1

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

code_puppy/cli_runner.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from code_puppy import __version__, callbacks, get_core_plugins_version, plugins
2424
from code_puppy.agents import get_current_agent
25-
from code_puppy.i18n import t
25+
from code_puppy.i18n import t, use_detected_locale
2626
from code_puppy.command_line.attachments import (
2727
parse_prompt_attachments,
2828
resolve_user_prompt,
@@ -1582,9 +1582,17 @@ def _force_utf8_stdio():
15821582
pass
15831583

15841584

1585+
def _initialize_locale():
1586+
"""Select the UI locale before any startup message is translated."""
1587+
from code_puppy.config import get_value
1588+
1589+
use_detected_locale(get_value("locale"))
1590+
1591+
15851592
def main_entry():
15861593
"""Entry point for the installed CLI tool."""
15871594
_force_utf8_stdio()
1595+
_initialize_locale()
15881596
try:
15891597
# Capture main()'s return so plugins / normal paths set the exit status
15901598
# (None → 0 or an int exit code).

tests/i18n/test_agent_manager_i18n.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
"""Coverage for the agent manager's user-facing message extraction."""
1+
"""Catalog-level tests protect the agent manager's translation contract."""
22

33
import re
44

5-
import pytest
6-
75
from code_puppy.i18n import catalog, pseudo, translate
86

97
_PLACEHOLDER = re.compile(r"\{(\w+)\}")
108
_NAMESPACE = "agent_manager."
119

1210

13-
@pytest.fixture(autouse=True)
14-
def _reset_locale():
15-
translate.set_locale("en-US")
16-
catalog.reset()
17-
yield
18-
translate.set_locale("en-US")
19-
catalog.reset()
20-
21-
2211
def _keys(locale="en-US"):
2312
return [key for key in catalog.load_catalog(locale) if key.startswith(_NAMESPACE)]
2413

@@ -47,6 +36,14 @@ def test_catalog_translations_preserve_placeholders():
4736
assert source == set(_PLACEHOLDER.findall(catalogs["fr-CA"][key]))
4837

4938

39+
def test_environment_selected_locale_resolves_message(monkeypatch):
40+
monkeypatch.setenv("CODE_PUPPY_LOCALE", "es")
41+
translate.use_detected_locale()
42+
assert "Agente" in translate.t(
43+
"agent_manager.clone.source_not_found", agent_name="agent-x"
44+
)
45+
46+
5047
def test_dynamic_values_are_interpolated():
5148
translate.set_locale("es")
5249
assert "agent-x" in translate.t(

0 commit comments

Comments
 (0)