Say which stock phrase was discarded, instead of crashing on it

A transcript the hallucination filter throws away is named in the message
that says so, and the placeholder it goes into is called {text}. So is the
first parameter of t(), which made the call two values for one argument and
a TypeError: the user was told "Unexpected error" rather than what happened.

Both strings are positional-only now, so no placeholder can ever collide with
them again.
This commit is contained in:
yusufipk
2026-08-01 20:06:28 +07:00
parent bb3b0bcb94
commit 45779a6c50
+5 -2
View File
@@ -27,7 +27,10 @@ def language():
return _lang return _lang
def t(text, **kwargs): def t(text, /, **kwargs):
# The string is positional-only so that every name is free to be a
# placeholder: t("Discarded: {text}", text=…) would otherwise be two values
# for one argument, and fail at the moment the message is shown.
out = TR.get(text, text) if _lang == "tr" else text out = TR.get(text, text) if _lang == "tr" else text
return out.format(**kwargs) if kwargs else out return out.format(**kwargs) if kwargs else out
@@ -42,7 +45,7 @@ _TR_CASES = {
} }
def name(text, case=""): def name(text, /, case=""):
if _lang != "tr" or not case: if _lang != "tr" or not case:
return text return text
return _TR_CASES.get(case, {}).get(text, text) return _TR_CASES.get(case, {}).get(text, text)