2021-07-13 07:13:39 +02:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-03-23 09:02:39 +01:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
2022-05-03 15:58:38 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/text"
|
|
|
|
caos_errors "github.com/zitadel/zitadel/internal/errors"
|
|
|
|
admin_pb "github.com/zitadel/zitadel/pkg/grpc/admin"
|
2021-07-13 07:13:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) GetSupportedLanguages(ctx context.Context, req *admin_pb.GetSupportedLanguagesRequest) (*admin_pb.GetSupportedLanguagesResponse, error) {
|
2022-01-26 10:16:33 +01:00
|
|
|
langs, err := s.query.Languages(ctx)
|
2021-07-13 07:13:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &admin_pb.GetSupportedLanguagesResponse{Languages: text.LanguageTagsToStrings(langs)}, nil
|
|
|
|
}
|
2022-02-16 16:49:17 +01:00
|
|
|
|
|
|
|
func (s *Server) SetDefaultLanguage(ctx context.Context, req *admin_pb.SetDefaultLanguageRequest) (*admin_pb.SetDefaultLanguageResponse, error) {
|
2022-05-03 15:58:38 +02:00
|
|
|
lang, err := language.Parse(req.Language)
|
2022-02-16 16:49:17 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, caos_errors.ThrowInvalidArgument(err, "API-39nnf", "Errors.Language.Parse")
|
|
|
|
}
|
2022-05-03 15:58:38 +02:00
|
|
|
details, err := s.command.SetDefaultLanguage(ctx, lang)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &admin_pb.SetDefaultLanguageResponse{
|
|
|
|
Details: object.DomainToChangeDetailsPb(details),
|
|
|
|
}, nil
|
2022-02-16 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
2022-04-25 11:16:36 +02:00
|
|
|
func (s *Server) GetDefaultLanguage(ctx context.Context, _ *admin_pb.GetDefaultLanguageRequest) (*admin_pb.GetDefaultLanguageResponse, error) {
|
|
|
|
return &admin_pb.GetDefaultLanguageResponse{Language: authz.GetInstance(ctx).DefaultLanguage().String()}, nil
|
2022-02-16 16:49:17 +01:00
|
|
|
}
|