From 0aa4bc334ec8905c87c79ca706ffd1e939b29677 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 07:27:09 +0000 Subject: [PATCH] refactor(i18n): share article prefix helper Co-Authored-By: Virgil --- grammar.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/grammar.go b/grammar.go index c7d0647..16f5f4c 100644 --- a/grammar.go +++ b/grammar.go @@ -754,13 +754,7 @@ func ArticlePhrase(word string) string { lang := currentLangForGrammar() word = renderWord(lang, word) article := Article(word) - if article == "" { - return "" - } - if strings.HasSuffix(article, "'") { - return article + word - } - return article + " " + word + return prefixWithArticle(article, word) } // DefiniteArticle returns the language-specific definite article for a word. @@ -791,13 +785,7 @@ func DefinitePhrase(word string) string { lang := currentLangForGrammar() word = renderWord(lang, word) article := DefiniteArticle(word) - if article == "" { - return "" - } - if strings.HasSuffix(article, "'") { - return article + word - } - return article + " " + word + return prefixWithArticle(article, word) } func definiteArticleForCurrentLanguage(lowerWord, originalWord string) (string, bool) { @@ -871,6 +859,16 @@ func TemplateFuncs() template.FuncMap { } } +func prefixWithArticle(article, word string) string { + if article == "" || word == "" { + return "" + } + if strings.HasSuffix(article, "'") { + return article + word + } + return article + " " + word +} + // Progress returns a progress message: "Building..." func Progress(verb string) string { lang := currentLangForGrammar()