From 6bd8b1aa61204cc6bc0f2ae09cbfbe9754ab4085 Mon Sep 17 00:00:00 2001 From: fnetx Date: Wed, 14 Dec 2022 19:55:13 +0100 Subject: [PATCH] [I18N] Add Locale merger script (cherry picked from commit ecc3dae2acaf567cd6b2888cc5c582588c7bfc53) (cherry picked from commit c6c3fc6ace6b6aa4f4877c5a96da54899f2dc2fa) (cherry picked from commit 4833bd594a49b70896c023b41da8a87ba33add0e) [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 commit 71de77f5ae59617eadda9e4992f1867a7acb7f17) (cherry picked from commit 0b5195e4e4ee1c4829d7f4e127cc48d5c0eb3d72) (cherry picked from commit 1252e83f8c7b22e06bb37622900741caa209e9eb) (cherry picked from commit 2ceb1b2b5faa32ca71716ed4c98d18b0942909e7) (cherry picked from commit 59233055b1a8e9bc79c5501d6e2c2649a6d1b26b) (cherry picked from commit 378ed6a21e0a57c3bb5211eb8ade4db499cdd7d9) (cherry picked from commit 2d661119c3b8a8278458005273f6a32fa3216050) (cherry picked from commit 2a95ff4107786bbf6c5b141a42e2efbd1bb897f8) (cherry picked from commit 012b5444a80cf2aaa61b2b65efebfe0691725422) (cherry picked from commit 2aaee4f7c4132af6f9a6e0d9aafe0218603b8a5c) (cherry picked from commit 52b3f53cb7dfc86a1287baa40f5f5b6dce946a27) (cherry picked from commit 24e665abe748ff34163e7c870aa0b90ffca86c26) (cherry picked from commit 335f8b2bd1971ce3b39b57b2cfd6d8c9af85ab75) (cherry picked from commit da3890938b7a13a467520fccfa6187376eab3050) (cherry picked from commit 5d0cdd5fe228906d378152b2472f7399fa9e3c45) (cherry picked from commit ed8e299b59e903f025cbbae8769e10678372b4b8) (cherry picked from commit b38db49888a6f627ab6c440899c0f6ccc3d55979) (cherry picked from commit c19cb35acf947153458707d8431153b8f3de0cf1) (cherry picked from commit 45fc0e2dda954d57adab7c3fc261c4e89e9f010d) (cherry picked from commit e7ef7c26d1883977684cf2ab576743c3d4f2f19e) (cherry picked from commit 11d05b0dc5b4dac8b2f6bad6e1f02e32d93f1704) (cherry picked from commit 8f7287337e7f316191c78aff01fddb3fc04ba2bb) (cherry picked from commit 8351803ee197a18d1faf84765ce55ed9b7498f9b) (cherry picked from commit 0ebf3c0fc73577e4a6fc379efb0164836943644b) (cherry picked from commit 749d3b4f68db8fc6d1eca61d6b0eeb3b40b20e63) Replaced gitea links with forgejo - protected tags, webhooks (cherry picked from commit 12534649d06af0ac518714dc28916ccc08a5a87c) (cherry picked from commit 5ad3ff69d41502dd8b3ac5cd30729353683c4316) (cherry picked from commit a7a325b3f5de8fca6be552e0c98a5125858a8e0a) (cherry picked from commit 31d2cc455f5339fc78de08237b49e4c6200a27e9) (cherry picked from commit 99b71abfdb4a000f1081fca988bc5295cca18473) (cherry picked from commit b096317ac9a2436e5c1563c44c5aee4be6dd2f5d) (cherry picked from commit cbc5cfdfd690278a17f034c2b00d4b48cafba977) (cherry picked from commit 1c99fa3f709e2ffce36c135d098971152154b7b4) (cherry picked from commit abf26758f4c09fb411d35a7494eddc675b9ba154) (cherry picked from commit ccf53ef1d693bf26d4d12955e2543683d1f81654) (cherry picked from commit 9287916ac8f1a492a6d65a0c46135a6c180db7a6) (cherry picked from commit 1f646e43ef6713bdfa233f93b294c4656e62428d) (cherry picked from commit 162873dff6517dbf6857d102479e1d2f73d51015) (cherry picked from commit c41533138d6ea9bdc7b3fb196eb8b1b3827550ed) --- build/merge-forgejo-locales.go | 99 ++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 build/merge-forgejo-locales.go diff --git a/build/merge-forgejo-locales.go b/build/merge-forgejo-locales.go new file mode 100644 index 0000000000..730f51c62e --- /dev/null +++ b/build/merge-forgejo-locales.go @@ -0,0 +1,99 @@ +// 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", + `GitHub`, `Codeberg`, + "https://github.com/go-gitea/gitea", "https://codeberg.org/forgejo/forgejo", + "https://blog.gitea.io", "https://forgejo.org/news", + "https://docs.gitea.io/en-us/protected-tags/", "https://forgejo.org/docs/latest/user/protection/#protected-tags", + "https://docs.gitea.io/en-us/webhooks/", "https://forgejo.org/docs/latest/user/webhooks/", + ) + + 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) + } + } +}