From c331c29c054b3376dc2ee4b8e953aae7dac80148 Mon Sep 17 00:00:00 2001 From: Snider Date: Fri, 30 Jan 2026 14:51:46 +0000 Subject: [PATCH] refactor(i18n): extract type checks to check.go Move isVerbFormObject, isNounFormObject, hasPluralCategories, isPluralObject to dedicated file. Co-Authored-By: Claude Opus 4.5 --- pkg/i18n/check.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++ pkg/i18n/i18n.go | 49 --------------------------------------------- 2 files changed, 51 insertions(+), 49 deletions(-) create mode 100644 pkg/i18n/check.go diff --git a/pkg/i18n/check.go b/pkg/i18n/check.go new file mode 100644 index 00000000..8054ef49 --- /dev/null +++ b/pkg/i18n/check.go @@ -0,0 +1,51 @@ +// Package i18n provides internationalization for the CLI. +package i18n + +// isVerbFormObject checks if a map represents verb conjugation forms. +func isVerbFormObject(m map[string]any) bool { + _, hasBase := m["base"] + _, hasPast := m["past"] + _, hasGerund := m["gerund"] + return (hasBase || hasPast || hasGerund) && !isPluralObject(m) +} + +// isNounFormObject checks if a map represents noun forms (with gender). +// Noun form objects have "gender" field, distinguishing them from CLDR plural objects. +func isNounFormObject(m map[string]any) bool { + _, hasGender := m["gender"] + // Only consider it a noun form if it has a gender field + // This distinguishes noun forms from CLDR plural objects which use one/other + return hasGender +} + +// hasPluralCategories checks if a map has CLDR plural categories beyond one/other. +func hasPluralCategories(m map[string]any) bool { + _, hasZero := m["zero"] + _, hasTwo := m["two"] + _, hasFew := m["few"] + _, hasMany := m["many"] + return hasZero || hasTwo || hasFew || hasMany +} + +// isPluralObject checks if a map represents plural forms. +// Recognizes all CLDR plural categories: zero, one, two, few, many, other. +func isPluralObject(m map[string]any) bool { + _, hasZero := m["zero"] + _, hasOne := m["one"] + _, hasTwo := m["two"] + _, hasFew := m["few"] + _, hasMany := m["many"] + _, hasOther := m["other"] + + // It's a plural object if it has any plural category key + if !hasZero && !hasOne && !hasTwo && !hasFew && !hasMany && !hasOther { + return false + } + // But not if it contains nested objects (those are namespace containers) + for _, v := range m { + if _, isMap := v.(map[string]any); isMap { + return false + } + } + return true +} diff --git a/pkg/i18n/i18n.go b/pkg/i18n/i18n.go index 1207b3f1..68d7b768 100644 --- a/pkg/i18n/i18n.go +++ b/pkg/i18n/i18n.go @@ -316,55 +316,6 @@ func flattenWithGrammar(prefix string, data map[string]any, out map[string]Messa } } -// isVerbFormObject checks if a map represents verb conjugation forms. -func isVerbFormObject(m map[string]any) bool { - _, hasBase := m["base"] - _, hasPast := m["past"] - _, hasGerund := m["gerund"] - return (hasBase || hasPast || hasGerund) && !isPluralObject(m) -} - -// isNounFormObject checks if a map represents noun forms (with gender). -// Noun form objects have "gender" field, distinguishing them from CLDR plural objects. -func isNounFormObject(m map[string]any) bool { - _, hasGender := m["gender"] - // Only consider it a noun form if it has a gender field - // This distinguishes noun forms from CLDR plural objects which use one/other - return hasGender -} - -// hasPluralCategories checks if a map has CLDR plural categories beyond one/other. -func hasPluralCategories(m map[string]any) bool { - _, hasZero := m["zero"] - _, hasTwo := m["two"] - _, hasFew := m["few"] - _, hasMany := m["many"] - return hasZero || hasTwo || hasFew || hasMany -} - -// isPluralObject checks if a map represents plural forms. -// Recognizes all CLDR plural categories: zero, one, two, few, many, other. -func isPluralObject(m map[string]any) bool { - _, hasZero := m["zero"] - _, hasOne := m["one"] - _, hasTwo := m["two"] - _, hasFew := m["few"] - _, hasMany := m["many"] - _, hasOther := m["other"] - - // It's a plural object if it has any plural category key - if !hasZero && !hasOne && !hasTwo && !hasFew && !hasMany && !hasOther { - return false - } - // But not if it contains nested objects (those are namespace containers) - for _, v := range m { - if _, isMap := v.(map[string]any); isMap { - return false - } - } - return true -} - func detectLanguage(supported []language.Tag) string { langEnv := os.Getenv("LANG") if langEnv == "" {