feat: translation support
All checks were successful
continuous-integration/drone/push Build is passing

See #483
This commit is contained in:
2025-08-19 11:22:52 +02:00
parent 5cf6048ecb
commit 4e205cf13e
108 changed files with 11217 additions and 1645 deletions

62
pkg/i18n/i18n.go Normal file
View File

@ -0,0 +1,62 @@
package i18n
import (
"embed"
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"coopcloud.tech/abra/pkg/log"
"github.com/leonelquinteros/gotext"
)
//go:embed locales/*.mo
var assetFS embed.FS
var (
DefaultLocale = "en"
Locale = DefaultLocale
)
func LoadLocale() *gotext.Mo {
entries, err := assetFS.ReadDir("locales")
if err != nil {
log.Fatalf("i18n: unable to read embedded locales directory: %s", err)
}
var linguas []string
for _, entry := range entries {
if filepath.Ext(entry.Name()) == ".mo" {
fname := entry.Name()
fnameWithoutExt := strings.TrimSuffix(fname, filepath.Ext(fname))
linguas = append(linguas, fnameWithoutExt)
}
}
locale := os.Getenv("LANG")
if locale != "" {
if slices.Contains(linguas, locale) {
Locale = locale
} else {
log.Debugf("unsupported language: %s (want: %s)", locale, strings.Join(linguas, " "))
}
}
if Locale == DefaultLocale {
return gotext.NewMo()
}
b, err := assetFS.ReadFile(fmt.Sprintf("locales/%s.mo", Locale))
if err != nil {
log.Fatalf("i18n: %s", err)
}
mo := gotext.NewMo()
mo.Parse(b)
return mo
}
var G = LoadLocale().Get

4677
pkg/i18n/locales/abra.pot Normal file

File diff suppressed because it is too large Load Diff

BIN
pkg/i18n/locales/es.mo Normal file

Binary file not shown.

4903
pkg/i18n/locales/es.po Normal file

File diff suppressed because it is too large Load Diff