2021-07-13 05:13:39 +00:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-03-23 08:02:39 +00:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
2022-05-03 13:58:38 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
2022-04-26 23:01:45 +00: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 05:13:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) GetSupportedLanguages(ctx context.Context, req *admin_pb.GetSupportedLanguagesRequest) (*admin_pb.GetSupportedLanguagesResponse, error) {
|
2022-01-26 09:16:33 +00:00
|
|
|
langs, err := s.query.Languages(ctx)
|
2021-07-13 05:13:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &admin_pb.GetSupportedLanguagesResponse{Languages: text.LanguageTagsToStrings(langs)}, nil
|
|
|
|
}
|
2022-02-16 15:49:17 +00:00
|
|
|
|
|
|
|
func (s *Server) SetDefaultLanguage(ctx context.Context, req *admin_pb.SetDefaultLanguageRequest) (*admin_pb.SetDefaultLanguageResponse, error) {
|
2022-05-03 13:58:38 +00:00
|
|
|
lang, err := language.Parse(req.Language)
|
2022-02-16 15:49:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, caos_errors.ThrowInvalidArgument(err, "API-39nnf", "Errors.Language.Parse")
|
|
|
|
}
|
2022-05-03 13:58:38 +00: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 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 09:16:36 +00: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 15:49:17 +00:00
|
|
|
}
|