embed translation on startup

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2023-03-09 15:16:59 +01:00
parent cfca9ec4b1
commit 1fc2bbcb08
2 changed files with 7 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package service
import (
"bytes"
"context"
"embed"
"errors"
"strings"
"text/template"
@@ -19,12 +20,15 @@ import (
ehmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/eventhistory/v0"
)
//go:embed l10n/locale
var _translationFS embed.FS
var (
_resourceTypeSpace = "storagespace"
_resourceTypeShare = "share"
// TODO: from config
_pathToLocales = "/home/jkoberg/ocis/services/userlog/pkg/service/locales"
_pathToLocales = "/home/jkoberg/ocis/services/userlog/l10n/locale"
_domain = "default"
)
@@ -281,7 +285,7 @@ func composeMessage(nt NotificationTemplate, locale string, vars map[string]inte
func loadTemplates(nt NotificationTemplate, locale string) (string, string) {
// Create Locale with library path and language code and load default domain
l := gotext.NewLocale(_pathToLocales, locale)
l := gotext.NewLocaleFS("l10n/locale", locale, _translationFS)
l.AddDomain(_domain)
return l.Get(nt.Subject), l.Get(nt.Message)
}

View File

@@ -384,7 +384,7 @@ func getSpace(ctx context.Context, spaceID string, gwc gateway.GatewayAPIClient)
}
if res.GetStatus().GetCode() != rpc.Code_CODE_OK {
return nil, fmt.Errorf("Unexpected status code while getting space: %v", res.GetStatus().GetCode())
return nil, fmt.Errorf("Error while getting space: (%v) %s", res.GetStatus().GetCode(), res.GetStatus().GetMessage())
}
if len(res.StorageSpaces) == 0 {