feat(i18n): localize failure prefix

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 08:23:19 +00:00
parent 9a846ae05b
commit 92b2f2ce94
3 changed files with 35 additions and 4 deletions

View file

@ -913,11 +913,21 @@ func ActionFailed(verb, subject string) string {
if verb == "" {
return ""
}
verb = renderWord(currentLangForGrammar(), verb)
lang := currentLangForGrammar()
verb = renderWord(lang, verb)
prefix := failedPrefix(lang)
if subject == "" {
return "Failed to " + verb
return prefix + " " + verb
}
return "Failed to " + verb + " " + renderWord(currentLangForGrammar(), subject)
return prefix + " " + verb + " " + renderWord(lang, subject)
}
func failedPrefix(lang string) string {
prefix := renderWord(lang, "failed_to")
if prefix == "" || prefix == "failed_to" {
return "Failed to"
}
return prefix
}
// Label returns a label with suffix: "Status:" (EN) or "Statut :" (FR)

View file

@ -841,6 +841,26 @@ func TestActionFailed_RespectsWordMap(t *testing.T) {
}
}
func TestActionFailedFrenchLocale(t *testing.T) {
prev := Default()
svc, err := New()
if err != nil {
t.Fatalf("New() failed: %v", err)
}
SetDefault(svc)
t.Cleanup(func() {
SetDefault(prev)
})
if err := SetLanguage("fr"); err != nil {
t.Fatalf("SetLanguage(fr) failed: %v", err)
}
if got, want := ActionFailed("supprimer", ""), "Impossible de supprimer"; got != want {
t.Fatalf("ActionFailed(%q, %q) = %q, want %q", "supprimer", "", got, want)
}
}
func TestGrammarData_Signals(t *testing.T) {
svc, err := New()
if err != nil {

View file

@ -92,7 +92,8 @@
"ssh": "SSH",
"ssl": "SSL",
"pr": "PR",
"ci": "CI"
"ci": "CI",
"failed_to": "Impossible de"
},
"punct": {
"label": " :",