Files
Курнат Андрей 2315f25754 Initial QSfera import
2026-06-07 10:20:04 +03:00

33 lines
919 B
Go

package l10n
import (
"embed"
"github.com/qsfera/server/pkg/l10n"
)
var (
//go:embed locale
_localeFS embed.FS
)
const (
// subfolder where the translation files are stored
_localeSubPath = "locale"
// domain of the graph service (transifex)
_domain = "graph"
)
// Translate translates a string based on the locale and default locale
func Translate(content, locale, defaultLocale, translationPath string) string {
t := l10n.NewTranslatorFromCommonConfig(defaultLocale, _domain, translationPath, _localeFS, _localeSubPath)
return t.Translate(content, locale)
}
// TranslateEntity returns a function that translates a struct or slice based on the locale
func TranslateEntity(locale, defaultLocale string, entity any, opts ...l10n.TranslateOption) error {
t := l10n.NewTranslatorFromCommonConfig(defaultLocale, _domain, "", _localeFS, _localeSubPath)
return t.TranslateEntity(locale, entity, opts...)
}