diff --git a/.deadcode-out b/.deadcode-out index 31184826ae..5b5698c5de 100644 --- a/.deadcode-out +++ b/.deadcode-out @@ -192,6 +192,9 @@ forgejo.org/modules/translation MockLocale.HasKey MockLocale.PrettyNumber +forgejo.org/modules/translation/localeiter + IterateMessagesContent + forgejo.org/modules/util OptionalArg diff --git a/build/lint-locale-usage/lint-locale-usage.go b/build/lint-locale-usage/lint-locale-usage.go index edbd086d0e..88375c1c36 100644 --- a/build/lint-locale-usage/lint-locale-usage.go +++ b/build/lint-locale-usage/lint-locale-usage.go @@ -18,8 +18,8 @@ import ( tmplParser "text/template/parse" "forgejo.org/modules/container" - "forgejo.org/modules/locale" fjTemplates "forgejo.org/modules/templates" + "forgejo.org/modules/translation/localeiter" "forgejo.org/modules/util" ) @@ -300,10 +300,6 @@ func main() { } msgids := make(container.Set[string]) - onMsgid := func(trKey, trValue string) error { - msgids[trKey] = struct{}{} - return nil - } localeFile := filepath.Join(filepath.Join("options", "locale"), "locale_en-US.ini") localeContent, err := os.ReadFile(localeFile) @@ -312,7 +308,10 @@ func main() { os.Exit(2) } - if err = locale.IterateMessagesContent(localeContent, onMsgid); err != nil { + if err = localeiter.IterateMessagesContent(localeContent, func(trKey, trValue string) error { + msgids[trKey] = struct{}{} + return nil + }); err != nil { fmt.Printf("%s:\tERROR: %s\n", localeFile, err.Error()) os.Exit(2) } @@ -324,7 +323,11 @@ func main() { os.Exit(2) } - if err := locale.IterateMessagesNextContent(localeContent, onMsgid); err != nil { + if err := localeiter.IterateMessagesNextContent(localeContent, func(trKey, pluralForm, trValue string) error { + // ignore plural form + msgids[trKey] = struct{}{} + return nil + }); err != nil { fmt.Printf("%s:\tERROR: %s\n", localeFile, err.Error()) os.Exit(2) } diff --git a/build/lint-locale/lint-locale.go b/build/lint-locale/lint-locale.go index 94ce941e62..0d80ffa4b0 100644 --- a/build/lint-locale/lint-locale.go +++ b/build/lint-locale/lint-locale.go @@ -14,7 +14,7 @@ import ( "slices" "strings" - "forgejo.org/modules/locale" + "forgejo.org/modules/translation/localeiter" "github.com/microcosm-cc/bluemonday" "github.com/sergi/go-diff/diffmatchpatch" @@ -100,7 +100,7 @@ func checkValue(trKey, value string) []string { func checkLocaleContent(localeContent []byte) []string { errors := []string{} - if err := locale.IterateMessagesContent(localeContent, func(trKey, trValue string) error { + if err := localeiter.IterateMessagesContent(localeContent, func(trKey, trValue string) error { errors = append(errors, checkValue(trKey, trValue)...) return nil }); err != nil { @@ -113,8 +113,12 @@ func checkLocaleContent(localeContent []byte) []string { func checkLocaleNextContent(localeContent []byte) []string { errors := []string{} - if err := locale.IterateMessagesNextContent(localeContent, func(trKey, trValue string) error { - errors = append(errors, checkValue(trKey, trValue)...) + if err := localeiter.IterateMessagesNextContent(localeContent, func(trKey, pluralForm, trValue string) error { + fullKey := trKey + if pluralForm != "" { + fullKey = trKey + "." + pluralForm + } + errors = append(errors, checkValue(fullKey, trValue)...) return nil }); err != nil { panic(err) diff --git a/build/lint-locale/lint-locale_test.go b/build/lint-locale/lint-locale_test.go index 37407461c7..d481a80e37 100644 --- a/build/lint-locale/lint-locale_test.go +++ b/build/lint-locale/lint-locale_test.go @@ -91,4 +91,16 @@ func TestNextLocalizationPolicy(t *testing.T) { "settings.hidden_comment_types_description": "\"