WIP: feat: translation support
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
See #483
This commit is contained in:
@ -1,30 +1,31 @@
|
||||
package lang
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
)
|
||||
|
||||
//go:embed locales
|
||||
var assetFS embed.FS
|
||||
|
||||
func GetLocale() string {
|
||||
if loc := os.Getenv("LC_MESSAGES"); loc != "" {
|
||||
return NormalizeLocale(loc)
|
||||
}
|
||||
|
||||
if loc := os.Getenv("LANG"); loc != "" {
|
||||
return NormalizeLocale(loc)
|
||||
}
|
||||
|
||||
return "C.UTF-8"
|
||||
return os.Getenv("LANG")
|
||||
}
|
||||
|
||||
func NormalizeLocale(loc string) string {
|
||||
if idx := strings.Index(loc, "."); idx != -1 {
|
||||
return loc[:idx]
|
||||
func LoadLocale(locale string) error {
|
||||
localePath := fmt.Sprintf("locales/%s/%s.po", locale)
|
||||
|
||||
b, err := assetFS.ReadFile(localePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load %s: %s", localePath, err)
|
||||
}
|
||||
|
||||
if idx := strings.Index(loc, "@"); idx != -1 {
|
||||
return loc[:idx]
|
||||
}
|
||||
po := gotext.NewPo()
|
||||
po.Parse(b)
|
||||
gotext.GetStorage().AddTranslator("abra", po)
|
||||
|
||||
return loc
|
||||
return nil
|
||||
}
|
||||
|
48
pkg/lang/locales/abra.pot
Normal file
48
pkg/lang/locales/abra.pot
Normal file
@ -0,0 +1,48 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Language: \n"
|
||||
"X-Generator: xgotext\n"
|
||||
|
||||
#: volumes.go:63
|
||||
msgid "%d retries failed"
|
||||
msgstr ""
|
||||
|
||||
#: volumes.go:59
|
||||
msgid "%s: waiting %d seconds before next retry"
|
||||
msgstr ""
|
||||
|
||||
#: configs.go:35
|
||||
msgid "conf %s: %s"
|
||||
msgstr ""
|
||||
|
||||
#: context.go:66
|
||||
msgid "context 'default' cannot be removed"
|
||||
msgstr ""
|
||||
|
||||
#: client.go:88
|
||||
msgid "created client for %s"
|
||||
msgstr ""
|
||||
|
||||
#: context.go:26
|
||||
msgid "created the %s context"
|
||||
msgstr ""
|
||||
|
||||
#: registry.go:20
|
||||
msgid "failed to parse image %s, saw: %s"
|
||||
msgstr ""
|
||||
|
||||
#: client.go:97
|
||||
msgid "swarm mode not enabled on %s?"
|
||||
msgstr ""
|
||||
|
||||
#: client.go:100
|
||||
msgid "swarm mode not enabled on local server?"
|
||||
msgstr ""
|
||||
|
||||
#: client.go:44
|
||||
msgid "unknown server, run 'abra server add %s'?"
|
||||
msgstr ""
|
20
pkg/lang/locales/es/LC_MESSAGES/es.po
Normal file
20
pkg/lang/locales/es/LC_MESSAGES/es.po
Normal file
@ -0,0 +1,20 @@
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2025-08-04 14:15+0000\n"
|
||||
"PO-Revision-Date: 2025-08-04 14:15+0000\n"
|
||||
"Last-Translator: 3wordchant <3wc.coopcloud@doesthisthing.work>\n"
|
||||
"Language-Team: Spanish <https://translate.coopcloud.tech/projects/"
|
||||
"co-op-cloud/abra/es/>\n"
|
||||
"Language: es\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: ENCODING\n"
|
||||
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
||||
"X-Generator: Weblate 5.12.2\n"
|
||||
|
||||
#: app.go:11
|
||||
msgid "Manage apps"
|
||||
msgstr "Gestionar aplicaciones"
|
Reference in New Issue
Block a user