From c83329b90a5ddf9a37025e007b872e04da9975a8 Mon Sep 17 00:00:00 2001 From: Virgil Date: Wed, 1 Apr 2026 06:51:45 +0000 Subject: [PATCH] fix(grammar): handle elided French article phrases Co-Authored-By: Virgil --- grammar.go | 4 ++++ grammar_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/grammar.go b/grammar.go index 6d0693b..fdfa01b 100644 --- a/grammar.go +++ b/grammar.go @@ -2,6 +2,7 @@ package i18n import ( "maps" + "strings" "text/template" "unicode" @@ -561,6 +562,9 @@ func ArticlePhrase(word string) string { if article == "" || word == "" { return "" } + if strings.HasSuffix(article, "'") { + return article + word + } return article + " " + word } diff --git a/grammar_test.go b/grammar_test.go index 1fe2710..e923379 100644 --- a/grammar_test.go +++ b/grammar_test.go @@ -366,6 +366,40 @@ func TestArticlePhrase(t *testing.T) { } } +func TestArticlePhraseFrenchLocale(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) + } + + tests := []struct { + word string + want string + }{ + {"branche", "la branche"}, + {"enfant", "l'enfant"}, + {"fichier", "le fichier"}, + } + + for _, tt := range tests { + t.Run(tt.word, func(t *testing.T) { + got := ArticlePhrase(tt.word) + if got != tt.want { + t.Errorf("ArticlePhrase(%q) = %q, want %q", tt.word, got, tt.want) + } + }) + } +} + func TestLabel(t *testing.T) { svc, err := New() if err != nil { -- 2.45.3