Merge remote-tracking branch 'forgejo/v1.19/forgejo-i18n' into v1.19/forgejo

This commit is contained in:
Earl Warren 2023-05-10 18:53:07 +02:00
commit 3e8f99287a
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
33 changed files with 106 additions and 8 deletions

3
.gitignore vendored
View file

@ -115,3 +115,6 @@ prime/
# Manpage
/man
# Generated merged Forgejo+Gitea language files
/options/locale/locale_*

View file

@ -774,10 +774,14 @@ generate: generate-backend
generate-backend: $(TAGS_PREREQ) generate-go
.PHONY: generate-go
generate-go: $(TAGS_PREREQ)
generate-go: $(TAGS_PREREQ) merge-locales
@echo "Running go generate..."
@CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES)
.PHONY: merge-locales
merge-locales:
$(GO) run build/merge-forgejo-locales.go
.PHONY: security-check
security-check:
go run $(GOVULNCHECK_PACKAGE) -v ./...
@ -936,13 +940,7 @@ lockfile-check:
.PHONY: update-translations
update-translations:
mkdir -p ./translations
cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
rm ./translations/gitea.zip
$(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
$(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
mv ./translations/*.ini ./options/locale/
rmdir ./translations
# noop to detect merge conflicts (potentially needs updating the scripts) and avoid breaking with Gitea
.PHONY: generate-license
generate-license:

View file

@ -0,0 +1,97 @@
// Copyright 2022 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.
//go:build ignore
package main
import (
"bufio"
"os"
"regexp"
"strings"
"gopkg.in/ini.v1"
)
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)
}
replacer := strings.NewReplacer(
"Gitea", "Forgejo",
"https://docs.gitea.io/en-us/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://code.gitea.io/gitea", "https://forgejo.org/download",
"code.gitea.io/gitea", "Forgejo",
`<a href="https://github.com/go-gitea/gitea/issues" target="_blank">GitHub</a>`, `<a href="https://codeberg.org/forgejo/forgejo/issues" target="_blank">Codeberg</a>`,
"https://github.com/go-gitea/gitea", "https://codeberg.org/forgejo/forgejo",
"https://blog.gitea.io", "https://forgejo.org/news",
)
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("\n"+line+"\n")...)
} else if strings.HasPrefix(line, "settings.web_hook_name_gitea") {
out = append(out, []byte("\n"+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 {
out = append(out, []byte(replacer.Replace(line)+"\n")...)
}
}
file.Close()
return out
}
func main() {
locales := generate_locale_list()
var err error
var localeFile *ini.File
for _, locale := range locales {
giteaLocale := sourceFolder + "gitea_" + locale
localeFile, err = ini.LoadSources(ini.LoadOptions{
IgnoreInlineComment: true,
}, giteaLocale, renameGiteaForgejo(giteaLocale))
if err != nil {
panic(err)
}
err = localeFile.SaveTo("options/locale/locale_" + locale)
if err != nil {
panic(err)
}
}
}