mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-09-12 09:51:19 +02:00
[I18N] Add Locale merger script
(cherry picked from commitecc3dae2ac
) (cherry picked from commitc6c3fc6ace
) (cherry picked from commit4833bd594a
) [I18N] in the home page replace GitHub with Forgejo The english string that shows on the home page to encourage for contribution no longer reference GitHub. But some translations still do. In this context, and this context only, replace it with Forgejo even though it may not be correct in some cases. Refs: https://codeberg.org/forgejo/forgejo/pulls/450 (cherry picked from commit71de77f5ae
) (cherry picked from commit0b5195e4e4
) (cherry picked from commit1252e83f8c
) (cherry picked from commit2ceb1b2b5f
) (cherry picked from commit59233055b1
) (cherry picked from commit378ed6a21e
) (cherry picked from commit2d661119c3
) (cherry picked from commit2a95ff4107
) (cherry picked from commit012b5444a8
) (cherry picked from commit2aaee4f7c4
) (cherry picked from commit52b3f53cb7
) (cherry picked from commit24e665abe7
) (cherry picked from commit335f8b2bd1
) (cherry picked from commitda3890938b
) (cherry picked from commit5d0cdd5fe2
) (cherry picked from commited8e299b59
) (cherry picked from commitb38db49888
) (cherry picked from commitc19cb35acf
) (cherry picked from commit45fc0e2dda
) (cherry picked from commite7ef7c26d1
) (cherry picked from commit11d05b0dc5
) (cherry picked from commit8f7287337e
) (cherry picked from commit8351803ee1
) (cherry picked from commit0ebf3c0fc7
) (cherry picked from commit749d3b4f68
) Replaced gitea links with forgejo - protected tags, webhooks (cherry picked from commit12534649d0
) (cherry picked from commit5ad3ff69d4
) (cherry picked from commita7a325b3f5
) (cherry picked from commit31d2cc455f
) (cherry picked from commit99b71abfdb
) (cherry picked from commitb096317ac9
) (cherry picked from commitcbc5cfdfd6
) (cherry picked from commit1c99fa3f70
) (cherry picked from commitabf26758f4
) (cherry picked from commitccf53ef1d6
) (cherry picked from commit9287916ac8
) (cherry picked from commit1f646e43ef
) (cherry picked from commit162873dff6
) (cherry picked from commitc41533138d
) (cherry picked from commit6bd8b1aa61
) (cherry picked from commitfc2decb959
) [I18N] Add Locale merger script (squash) abort on NOOP If a string is no longer used in the english version of the locales, it means the Gitea string was changed and it needs updating. Abort when it is the case and recommend action. (cherry picked from commit34f3d7d65e
) (cherry picked from commit666aa258ad
) (cherry picked from commitf9655eebeb
) (cherry picked from commitf6979b0aac
) (cherry picked from commitc3c62bea76
) (cherry picked from commitd69cab8b95
) (cherry picked from commit521184d6a6
)
This commit is contained in:
parent
54dd7d13a1
commit
987425d6de
117
build/merge-forgejo-locales.go
Normal file
117
build/merge-forgejo-locales.go
Normal file
|
@ -0,0 +1,117 @@
|
|||
// 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"
|
||||
"log"
|
||||
"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)
|
||||
}
|
||||
|
||||
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",
|
||||
`<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",
|
||||
"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("\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 {
|
||||
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() {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue