fix(i18n): honour word map in action failures

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 07:23:49 +00:00
parent 69bf91b1b9
commit d2017eb6e3
2 changed files with 31 additions and 0 deletions

View file

@ -915,6 +915,7 @@ func ActionFailed(verb, subject string) string {
if verb == "" {
return ""
}
verb = renderWord(currentLangForGrammar(), verb)
if subject == "" {
return "Failed to " + verb
}

View file

@ -811,6 +811,36 @@ func TestActionFailed(t *testing.T) {
}
}
func TestActionFailed_RespectsWordMap(t *testing.T) {
prev := Default()
svc, err := New()
if err != nil {
t.Fatalf("New() failed: %v", err)
}
SetDefault(svc)
t.Cleanup(func() {
SetDefault(prev)
})
data := GetGrammarData("en")
if data == nil {
t.Fatal("GetGrammarData(\"en\") returned nil")
}
original, existed := data.Words["push"]
data.Words["push"] = "submit"
t.Cleanup(func() {
if existed {
data.Words["push"] = original
return
}
delete(data.Words, "push")
})
if got, want := ActionFailed("push", "commits"), "Failed to submit commits"; got != want {
t.Fatalf("ActionFailed(%q, %q) = %q, want %q", "push", "commits", got, want)
}
}
func TestGrammarData_Signals(t *testing.T) {
svc, err := New()
if err != nil {