diff --git a/ocis-pkg/l10n/l10n.go b/ocis-pkg/l10n/l10n.go index 40bcced63d..723f901eb2 100644 --- a/ocis-pkg/l10n/l10n.go +++ b/ocis-pkg/l10n/l10n.go @@ -54,33 +54,38 @@ func (t Translator) Translate(str, locale string) string { return t.Locale(locale).Get(str) } -func TranslateLocation(t Translator, locale string) func(string, ...any) string { - return t.Locale(locale).Get -} - type structs func() []any type maps func() []any type each func() []any type field func() string +// TranslateField function provides the generic way to translate the necessary field in composite entities. func TranslateField(fieldName string) field { return func() string { return fieldName } } +// TranslateStruct function provides the generic way to translate the nested fields in composite entities. +// When the TranslateStruct function is used right after the TranslateEntity, the first argument must be the entity itself, +// the rest of the arguments are the fields to translate or nested function. func TranslateStruct(args ...any) structs { return func() []any { return args } } +// TranslateMap function provides the generic way to translate the necessary fields in maps. +// It's not implemented yet. func TranslateMap(args ...any) maps { return func() []any { return args } } +// TranslateEach function provides the generic way to translate the necessary fields in slices or nested entities. +// When the TranslateEach function is used right after the TranslateEntity, the first argument must be the slice itself, +// the rest of the arguments are nested function or no arguments if the slice contains only strings. func TranslateEach(args ...any) each { return func() []any { return args diff --git a/services/graph/pkg/l10n/translation.go b/services/graph/pkg/l10n/translation.go index ded91ade6b..47d72af8cb 100644 --- a/services/graph/pkg/l10n/translation.go +++ b/services/graph/pkg/l10n/translation.go @@ -19,11 +19,13 @@ const ( _domain = "graph" ) +// Translate translates a string based on the locale and default locale func Translate(content, locale, defaultLocale string) string { t := l10npkg.NewTranslatorFromCommonConfig(defaultLocale, _domain, "", _localeFS, _localeSubPath) return t.Translate(content, locale) } +// NewTranslateLocation returns a function that translates a string based on the locale func NewTranslateLocation(locale, defaultLocale string) func(string, ...any) string { t := l10npkg.NewTranslatorFromCommonConfig(defaultLocale, _domain, "", _localeFS, _localeSubPath) return t.Locale(locale).Get