Skip to content

Commit 3e8f992

Browse files
committed
Merge remote-tracking branch 'forgejo/v1.19/forgejo-i18n' into v1.19/forgejo
2 parents b2289c5 + 9423459 commit 3e8f992

33 files changed

+106
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,6 @@ prime/
115115

116116
# Manpage
117117
/man
118+
119+
# Generated merged Forgejo+Gitea language files
120+
/options/locale/locale_*

Makefile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,14 @@ generate: generate-backend
774774
generate-backend: $(TAGS_PREREQ) generate-go
775775

776776
.PHONY: generate-go
777-
generate-go: $(TAGS_PREREQ)
777+
generate-go: $(TAGS_PREREQ) merge-locales
778778
@echo "Running go generate..."
779779
@CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES)
780780

781+
.PHONY: merge-locales
782+
merge-locales:
783+
$(GO) run build/merge-forgejo-locales.go
784+
781785
.PHONY: security-check
782786
security-check:
783787
go run $(GOVULNCHECK_PACKAGE) -v ./...
@@ -936,13 +940,7 @@ lockfile-check:
936940

937941
.PHONY: update-translations
938942
update-translations:
939-
mkdir -p ./translations
940-
cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
941-
rm ./translations/gitea.zip
942-
$(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
943-
$(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
944-
mv ./translations/*.ini ./options/locale/
945-
rmdir ./translations
943+
# noop to detect merge conflicts (potentially needs updating the scripts) and avoid breaking with Gitea
946944

947945
.PHONY: generate-license
948946
generate-license:

build/merge-forgejo-locales.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright 2022 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build ignore
6+
7+
package main
8+
9+
import (
10+
"bufio"
11+
"os"
12+
"regexp"
13+
"strings"
14+
15+
"gopkg.in/ini.v1"
16+
)
17+
18+
const (
19+
trimPrefix = "gitea_"
20+
sourceFolder = "options/locales/"
21+
)
22+
23+
// returns list of locales, still containing the file extension!
24+
func generate_locale_list() []string {
25+
localeFiles, _ := os.ReadDir(sourceFolder)
26+
locales := []string{}
27+
for _, localeFile := range localeFiles {
28+
if !localeFile.IsDir() && strings.HasPrefix(localeFile.Name(), trimPrefix) {
29+
locales = append(locales, strings.TrimPrefix(localeFile.Name(), trimPrefix))
30+
}
31+
}
32+
return locales
33+
}
34+
35+
// replace all occurrences of Gitea with Forgejo
36+
func renameGiteaForgejo(filename string) []byte {
37+
file, err := os.Open(filename)
38+
if err != nil {
39+
panic(err)
40+
}
41+
42+
replacer := strings.NewReplacer(
43+
"Gitea", "Forgejo",
44+
"https://docs.gitea.io/en-us/install-from-binary/", "https://forgejo.org/download/#installation-from-binary",
45+
"https://github.com/go-gitea/gitea/tree/master/docker", "https://forgejo.org/download/#container-image",
46+
"https://docs.gitea.io/en-us/install-from-package/", "https://forgejo.org/download",
47+
"https://code.gitea.io/gitea", "https://forgejo.org/download",
48+
"code.gitea.io/gitea", "Forgejo",
49+
`<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>`,
50+
"https://github.com/go-gitea/gitea", "https://codeberg.org/forgejo/forgejo",
51+
"https://blog.gitea.io", "https://forgejo.org/news",
52+
)
53+
54+
out := make([]byte, 0, 1024)
55+
scanner := bufio.NewScanner(file)
56+
scanner.Split(bufio.ScanLines)
57+
for scanner.Scan() {
58+
line := scanner.Text()
59+
60+
if strings.HasPrefix(line, "license_desc=") {
61+
line = strings.Replace(line, "GitHub", "Forgejo", 1)
62+
}
63+
64+
if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
65+
out = append(out, []byte("\n"+line+"\n")...)
66+
} else if strings.HasPrefix(line, "settings.web_hook_name_gitea") {
67+
out = append(out, []byte("\n"+line+"\n")...)
68+
out = append(out, []byte("settings.web_hook_name_forgejo = Forgejo\n")...)
69+
} else if strings.HasPrefix(line, "migrate.gitea.description") {
70+
re := regexp.MustCompile(`(.*Gitea)`)
71+
out = append(out, []byte(re.ReplaceAllString(line, "${1}/Forgejo")+"\n")...)
72+
} else {
73+
out = append(out, []byte(replacer.Replace(line)+"\n")...)
74+
}
75+
}
76+
file.Close()
77+
return out
78+
}
79+
80+
func main() {
81+
locales := generate_locale_list()
82+
var err error
83+
var localeFile *ini.File
84+
for _, locale := range locales {
85+
giteaLocale := sourceFolder + "gitea_" + locale
86+
localeFile, err = ini.LoadSources(ini.LoadOptions{
87+
IgnoreInlineComment: true,
88+
}, giteaLocale, renameGiteaForgejo(giteaLocale))
89+
if err != nil {
90+
panic(err)
91+
}
92+
err = localeFile.SaveTo("options/locale/locale_" + locale)
93+
if err != nil {
94+
panic(err)
95+
}
96+
}
97+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)