Skip to content

Commit b63a871

Browse files
author
Loïc Dachary
committed
Merge remote-tracking branch 'forgejo/v1.18/forgejo-i18n' into v1.18/forgejo
2 parents 70cf3e7 + 8e80efc commit b63a871

33 files changed

+101
-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
@@ -748,10 +748,14 @@ generate: generate-backend
748748
generate-backend: $(TAGS_PREREQ) generate-go
749749

750750
.PHONY: generate-go
751-
generate-go: $(TAGS_PREREQ)
751+
generate-go: $(TAGS_PREREQ) merge-locales
752752
@echo "Running go generate..."
753753
@CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES)
754754

755+
.PHONY: merge-locales
756+
merge-locales:
757+
$(GO) run build/merge-forgejo-locales.go
758+
755759
.PHONY: security-check
756760
security-check:
757761
govulncheck -v ./...
@@ -908,13 +912,7 @@ lockfile-check:
908912

909913
.PHONY: update-translations
910914
update-translations:
911-
mkdir -p ./translations
912-
cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
913-
rm ./translations/gitea.zip
914-
$(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
915-
$(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
916-
mv ./translations/*.ini ./options/locale/
917-
rmdir ./translations
915+
# noop to detect merge conflicts (potentially needs updating the scripts) and avoid breaking with Gitea
918916

919917
.PHONY: generate-license
920918
generate-license:

build/merge-forgejo-locales.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
60+
out = append(out, []byte("\n"+line+"\n")...)
61+
} else if strings.HasPrefix(line, "settings.web_hook_name_gitea") {
62+
out = append(out, []byte("\n"+line+"\n")...)
63+
out = append(out, []byte("settings.web_hook_name_forgejo = Forgejo\n")...)
64+
} else if strings.HasPrefix(line, "migrate.gitea.description") {
65+
re := regexp.MustCompile(`(.*Gitea)`)
66+
out = append(out, []byte(re.ReplaceAllString(line, "${1}/Forgejo")+"\n")...)
67+
} else {
68+
out = append(out, []byte(replacer.Replace(line)+"\n")...)
69+
}
70+
}
71+
file.Close()
72+
return out
73+
}
74+
75+
func main() {
76+
locales := generate_locale_list()
77+
var err error
78+
var localeFile *ini.File
79+
for _, locale := range locales {
80+
giteaLocale := sourceFolder + "gitea_" + locale
81+
localeFile, err = ini.LoadSources(ini.LoadOptions{
82+
IgnoreInlineComment: true,
83+
}, giteaLocale, renameGiteaForgejo(giteaLocale))
84+
if err != nil {
85+
panic(err)
86+
}
87+
err = localeFile.SaveTo("options/locale/locale_" + locale)
88+
if err != nil {
89+
panic(err)
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)