From 0dd14393d296d9a0915a978f83ac2057b7e4d711 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Tue, 12 May 2026 17:31:50 +0200 Subject: ki18n: add gettext CI check for missing translation keys gettext now exits 1 when any key extracted from templates is absent from a locale file. Added as a task and wired into the check task. Co-Authored-By: Claude Sonnet 4.6 --- README.md | 9 ++++++--- Taskfile.yml | 5 +++++ ki18n/cmd/gettext/gettext.go | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9e6cf5a..aa436a4 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,17 @@ ## ki18n -- [ ] Add gettext to CI - ### Setup 1. Call `ki18n.Init(localesFS)` at startup with a filesystem containing `/*.yml` translation files. Pass extra `ki18n.Locale` values to register additional languages. 2. Register `ki18n.LangMiddleware(...)` on your router, passing one or more strategies in priority order. -3. Run `go run github.com/martinlehoux/kagamigo/cmd/gettext -write` to generate translation files. +3. Run `go run github.com/martinlehoux/kagamigo/ki18n/cmd/gettext -write` to generate translation files. 4. Complete the generated files. +5. Add the check to CI — exits 1 if any translation key is missing from a locale file: + +```sh +go run github.com/martinlehoux/kagamigo/ki18n/cmd/gettext +``` ### Language detection strategies diff --git a/Taskfile.yml b/Taskfile.yml index 0ba1f5f..7033429 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -6,6 +6,10 @@ tasks: cmds: - go tool templ generate + gettext: + cmds: + - go run github.com/martinlehoux/kagamigo/ki18n/cmd/gettext + check: cmds: - gofmt -d -e -s . @@ -17,6 +21,7 @@ tasks: - go test -race ./... - go tool revive - go mod tidy + - task gettext tools: cmds: diff --git a/ki18n/cmd/gettext/gettext.go b/ki18n/cmd/gettext/gettext.go index e68dd22..b3b47cd 100644 --- a/ki18n/cmd/gettext/gettext.go +++ b/ki18n/cmd/gettext/gettext.go @@ -174,6 +174,7 @@ func main() { extractedKeys := extractAllKeys() baseLogger.Info("extracted keys from templates", slog.Int("count", len(extractedKeys))) + missingKeys := false for _, lang := range langs { logger := baseLogger.With(slog.String("lang", lang)) currentLocales := getOrCreateLocale(lang, logger) @@ -201,6 +202,7 @@ func main() { if _, ok := currentLocales[key]; !ok { logger.Info(`found missing key`, slog.String("key", key)) newLocales[key] = "" + missingKeys = true } } var completion string @@ -217,4 +219,8 @@ func main() { kcore.Expect(os.WriteFile(filepath.Join("locales", lang, "index.yml"), content, 0o600), "error writing file") } } + + if missingKeys { + os.Exit(1) + } } -- cgit v1.3