From 6647e4d53f04f8d5585090c7f0cf266713542b4b Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Thu, 28 Mar 2024 17:29:32 +0100 Subject: [PATCH] [I18N] make merge-locales & build/merge-forgejo-locales.go are noop Instead of failing or do things that could be damaging, this script prints a deprecation notice. It fixes the unnecessary breaking change introduced in `[I18n] tooling and process`. https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/version-management/forgejo/default.nix#L80 $ make merge-locales NOT NEEDED: THIS IS A NOOP AS OF Forgejo 7.0 BUT KEPT FOR BACKWARD COMPATIBILITY $ go run build/merge-forgejo-locales.go NOT NEEDED: THIS IS A NOOP AS OF Forgejo 7.0 BUT KEPT FOR BACKWARD COMPATIBILITY Also remove the build/crowdin-to-weblate.sh script that was never needed. --- Makefile | 4 ++ build/crowdin-to-weblate.sh | 27 --------- build/merge-forgejo-locales.go | 100 +-------------------------------- 3 files changed, 7 insertions(+), 124 deletions(-) delete mode 100755 build/crowdin-to-weblate.sh diff --git a/Makefile b/Makefile index b1c4864c7a..70a7f906eb 100644 --- a/Makefile +++ b/Makefile @@ -814,6 +814,10 @@ generate-go: $(TAGS_PREREQ) @echo "Running go generate..." @CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES) +.PHONY: merge-locales +merge-locales: + @echo "NOT NEEDED: THIS IS A NOOP AS OF Forgejo 7.0 BUT KEPT FOR BACKWARD COMPATIBILITY" + .PHONY: security-check security-check: go run $(GOVULNCHECK_PACKAGE) ./... diff --git a/build/crowdin-to-weblate.sh b/build/crowdin-to-weblate.sh deleted file mode 100755 index 877b5d9e07..0000000000 --- a/build/crowdin-to-weblate.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# Copyright 2024 The Forgejo Authors -# SPDX-License-Identifier: MIT - -D=/tmp/crowdin-to-weblate -mkdir -p $D - -function checkout() { - if test -d $D/gitea ; then - git -C $D/gitea reset --hard - return - fi - - git clone --depth 1 https://github.com/go-gitea/gitea $D/gitea -} - -function replace() { - go run build/merge-forgejo-locales.go $D/gitea/options/locale - cp -a $D/gitea/options/locale/* options/locale -} - -function run() { - checkout - replace -} - -"$@" diff --git a/build/merge-forgejo-locales.go b/build/merge-forgejo-locales.go index eebe12578b..05c8d9b5e9 100644 --- a/build/merge-forgejo-locales.go +++ b/build/merge-forgejo-locales.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Forgejo Authors c/o Codeberg e.V.. All rights reserved. +// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -7,103 +7,9 @@ package main import ( - "bufio" - "log" - "os" - "regexp" - "strings" + "fmt" ) -const ( - trimPrefix = "gitea_" - sourceFolder = "options/locales/" -) - -// returns list of locales, still containing the file extension! -func generate_locale_list() []string { - localeFiles, _ := os.ReadDir(sourceFolder) - locales := []string{} - for _, localeFile := range localeFiles { - if !localeFile.IsDir() && strings.HasPrefix(localeFile.Name(), trimPrefix) { - locales = append(locales, strings.TrimPrefix(localeFile.Name(), trimPrefix)) - } - } - return locales -} - -// replace all occurrences of Gitea with Forgejo -func renameGiteaForgejo(filename string) []byte { - file, err := os.Open(filename) - if err != nil { - panic(err) - } - - replacements := []string{ - "Gitea", "Forgejo", - "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.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.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) - scanner.Split(bufio.ScanLines) - for scanner.Scan() { - line := scanner.Text() - - if strings.HasPrefix(line, "license_desc=") { - line = strings.Replace(line, "GitHub", "Forgejo", 1) - } - - if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") { - out = append(out, []byte(line+"\n")...) - } else if strings.HasPrefix(line, "settings.web_hook_name_gitea") { - out = append(out, []byte(line+"\n")...) - out = append(out, []byte("settings.web_hook_name_forgejo = Forgejo\n")...) - } else if strings.HasPrefix(line, "migrate.gitea.description") { - 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 -} - func main() { - d := os.Args[1] - files, err := os.ReadDir(d) - if err != nil { - log.Fatal(err) - } - - for _, f := range files { - p := d + "/" + f.Name() - os.WriteFile(p, renameGiteaForgejo(p), 0o644) - } + fmt.Println("NOT NEEDED: THIS IS A NOOP AS OF Forgejo 7.0 BUT KEPT FOR BACKWARD COMPATIBILITY") }