From bc59be2feac854ebdaa9c4d5462f35f5cde42c1c Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Tue, 28 Nov 2023 17:26:49 +0100 Subject: [PATCH] [I18N] Add Locale merger script (squash) abort on NOOP If a string is no longer used in the english version of the locales, it means the Gitea string was changed and it needs updating. Abort when it is the case and recommend action. --- build/merge-forgejo-locales.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/build/merge-forgejo-locales.go b/build/merge-forgejo-locales.go index 730f51c62e..3fecde12e2 100644 --- a/build/merge-forgejo-locales.go +++ b/build/merge-forgejo-locales.go @@ -8,6 +8,7 @@ package main import ( "bufio" + "log" "os" "regexp" "strings" @@ -39,19 +40,28 @@ func renameGiteaForgejo(filename string) []byte { panic(err) } - replacer := strings.NewReplacer( + replacements := []string{ "Gitea", "Forgejo", - "https://docs.gitea.io/en-us/install-from-binary/", "https://forgejo.org/download/#installation-from-binary", + "https://docs.gitea.com/installation/install-from-binary", "https://forgejo.org/download/#installation-from-binary", "https://github.com/go-gitea/gitea/tree/master/docker", "https://forgejo.org/download/#container-image", - "https://docs.gitea.io/en-us/install-from-package/", "https://forgejo.org/download", + "https://docs.gitea.com/installation/install-from-package", "https://forgejo.org/download", "https://code.gitea.io/gitea", "https://forgejo.org/download", "code.gitea.io/gitea", "Forgejo", `GitHub`, `Codeberg`, "https://github.com/go-gitea/gitea", "https://codeberg.org/forgejo/forgejo", "https://blog.gitea.io", "https://forgejo.org/news", - "https://docs.gitea.io/en-us/protected-tags/", "https://forgejo.org/docs/latest/user/protection/#protected-tags", - "https://docs.gitea.io/en-us/webhooks/", "https://forgejo.org/docs/latest/user/webhooks/", - ) + "https://docs.gitea.com/usage/protected-tags", "https://forgejo.org/docs/latest/user/protection/#protected-tags", + "https://docs.gitea.com/usage/webhooks", "https://forgejo.org/docs/latest/user/webhooks/", + } + replacer := strings.NewReplacer(replacements...) + replaced := make(map[string]bool, len(replacements)/2) + count_replaced := func(original string) { + for i := 0; i < len(replacements); i += 2 { + if strings.Contains(original, replacements[i]) { + replaced[replacements[i]] = true + } + } + } out := make([]byte, 0, 1024) scanner := bufio.NewScanner(file) @@ -72,10 +82,18 @@ func renameGiteaForgejo(filename string) []byte { re := regexp.MustCompile(`(.*Gitea)`) out = append(out, []byte(re.ReplaceAllString(line, "${1}/Forgejo")+"\n")...) } else { + count_replaced(line) out = append(out, []byte(replacer.Replace(line)+"\n")...) } } file.Close() + if strings.HasSuffix(filename, "gitea_en-US.ini") { + for i := 0; i < len(replacements); i += 2 { + if replaced[replacements[i]] == false { + log.Fatalf("%s was never used to replace something in %s, it is obsolete and must be updated", replacements[i], filename) + } + } + } return out }