2020-07-08 07:48:11 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-07-07 12:58:00 +00:00
|
|
|
"github.com/zitadel/logging"
|
2020-07-08 07:48:11 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
|
|
_ "github.com/zitadel/zitadel/internal/statik"
|
2023-01-19 15:50:05 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
2020-07-08 07:48:11 +00:00
|
|
|
)
|
|
|
|
|
2022-04-25 09:16:36 +00:00
|
|
|
func TranslationHandler() func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
2020-07-08 07:48:11 +00:00
|
|
|
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
|
|
|
resp, err := handler(ctx, req)
|
2023-01-19 15:50:05 +00:00
|
|
|
ctx, span := tracing.NewSpan(ctx)
|
|
|
|
defer func() { span.EndWithError(err) }()
|
|
|
|
|
2020-07-09 13:02:03 +00:00
|
|
|
if loc, ok := resp.(localizers); ok && resp != nil {
|
2023-01-19 15:50:05 +00:00
|
|
|
translator, translatorError := newZitadelTranslator(authz.GetInstance(ctx).DefaultLanguage())
|
|
|
|
if translatorError != nil {
|
|
|
|
logging.New().WithError(translatorError).Error("could not load translator")
|
|
|
|
return resp, err
|
|
|
|
}
|
2020-07-08 07:48:11 +00:00
|
|
|
translateFields(ctx, loc, translator)
|
|
|
|
}
|
2020-08-28 07:44:43 +00:00
|
|
|
if err != nil {
|
2023-01-19 15:50:05 +00:00
|
|
|
translator, translatorError := newZitadelTranslator(authz.GetInstance(ctx).DefaultLanguage())
|
|
|
|
if translatorError != nil {
|
|
|
|
logging.New().WithError(translatorError).Error("could not load translator")
|
|
|
|
return resp, err
|
|
|
|
}
|
2020-08-28 07:44:43 +00:00
|
|
|
err = translateError(ctx, err, translator)
|
|
|
|
}
|
2020-07-08 07:48:11 +00:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
}
|