1
0
mirror of https://github.com/zitadel/zitadel.git synced 2024-12-26 17:47:48 +00:00
Silvan 7b5135e637
fix(adminAPI): localize event type ()
* fix(adminAPI): localisation of event types, aggregate types
* fix(adminAPI): validations of ListEvent request
* implement caching of editor user information
2023-01-19 15:50:05 +00:00

39 lines
1.3 KiB
Go

package middleware
import (
"context"
"github.com/zitadel/logging"
"google.golang.org/grpc"
"github.com/zitadel/zitadel/internal/api/authz"
_ "github.com/zitadel/zitadel/internal/statik"
"github.com/zitadel/zitadel/internal/telemetry/tracing"
)
func TranslationHandler() func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
resp, err := handler(ctx, req)
ctx, span := tracing.NewSpan(ctx)
defer func() { span.EndWithError(err) }()
if loc, ok := resp.(localizers); ok && resp != nil {
translator, translatorError := newZitadelTranslator(authz.GetInstance(ctx).DefaultLanguage())
if translatorError != nil {
logging.New().WithError(translatorError).Error("could not load translator")
return resp, err
}
translateFields(ctx, loc, translator)
}
if err != nil {
translator, translatorError := newZitadelTranslator(authz.GetInstance(ctx).DefaultLanguage())
if translatorError != nil {
logging.New().WithError(translatorError).Error("could not load translator")
return resp, err
}
err = translateError(ctx, err, translator)
}
return resp, err
}
}