zitadel/internal/api/grpc/server/middleware/translation_interceptor.go
Fabi 7295383621
fix: translation (#647)
* fix: translation

* fix: translation

* fix: translation

* fix: remove unused code

* fix: log err
2020-08-28 09:44:43 +02:00

27 lines
730 B
Go

package middleware
import (
"context"
"golang.org/x/text/language"
"google.golang.org/grpc"
_ "github.com/caos/zitadel/internal/statik"
)
func TranslationHandler(defaultLanguage language.Tag) func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
translator := newZitadelTranslator(defaultLanguage)
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
resp, err := handler(ctx, req)
if loc, ok := resp.(localizers); ok && resp != nil {
translateFields(ctx, loc, translator)
}
if err != nil {
err = translateError(ctx, err, translator)
}
return resp, err
}
}