Merge branch 'forgejo-i18n' into forgejo
This commit is contained in:
commit
7c87f6c14e
33 changed files with 80 additions and 8 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -112,3 +112,6 @@ prime/
|
|||
|
||||
# Manpage
|
||||
/man
|
||||
|
||||
# Generated merged Forgejo+Gitea language files
|
||||
/options/locale/locale_*
|
||||
|
|
14
Makefile
14
Makefile
|
@ -739,10 +739,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 ./...
|
||||
|
@ -892,13 +896,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:
|
||||
|
|
71
build/merge-forgejo-locales.go
Normal file
71
build/merge-forgejo-locales.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
// 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"
|
||||
"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)
|
||||
}
|
||||
|
||||
out := make([]byte, 0, 1024)
|
||||
scanner := bufio.NewScanner(file)
|
||||
scanner.Split(bufio.ScanLines)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
|
||||
out = append(out, []byte("\n"+line+"\n")...)
|
||||
} else if strings.Contains(line, "Gitea") {
|
||||
out = append(out, []byte(strings.Replace(line, "Gitea", "Forgejo", -1)+"\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.Load(giteaLocale, renameGiteaForgejo(giteaLocale))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = localeFile.SaveTo("options/locale/locale_" + locale)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue