Unverified Commit e3b0c7bb authored by erda-bot's avatar erda-bot Committed by GitHub
Browse files

fix: convertion (#4140) (#4163)


* fix: convertion

* feat: add ut
Co-authored-by: default avatar悟空 <rainchan365@163.com>
parent f62a1322
Showing with 44 additions and 5 deletions
+44 -5
......@@ -339,7 +339,7 @@ func (r *Resource) GetClusterTrend(ctx context.Context, ordId int64, userId stri
start, _ = request.Query.GetStart()
end, _ = request.Query.GetEnd()
)
langCodes := ctx.Value(Lang).(i18n.LanguageCodes)
langCodes, _ := ctx.Value(Lang).(i18n.LanguageCodes)
td = &Histogram{
Name: r.I18n(langCodes, "cluster trend"),
}
......@@ -468,9 +468,9 @@ func (r *Resource) GetClusterTrend(ctx context.Context, ordId int64, userId stri
func (r *Resource) GetProjectTrend(ctx context.Context, request *apistructs.TrendRequest) (*Histogram, error) {
var (
//l = logrus.WithField("func", "*Resource.GetProjectTrend")
langCodes = ctx.Value(Lang).(i18n.LanguageCodes)
td = new(Histogram)
orgID, _ = request.GetOrgID()
langCodes, _ = ctx.Value(Lang).(i18n.LanguageCodes)
td = new(Histogram)
orgID, _ = request.GetOrgID()
//userID, _ = request.GetUserID()
start, _ = request.Query.GetStart()
end, _ = request.Query.GetEnd()
......
......@@ -45,7 +45,7 @@ func WithI18nCodes(h Handler) Handler {
func UnwrapI18nCodes(ctx context.Context) i18nProviders.LanguageCodes {
var lang struct{ Lang string }
if codes := ctx.Value(lang).(i18nProviders.LanguageCodes); len(codes) > 0 {
if codes, _ := ctx.Value(lang).(i18nProviders.LanguageCodes); len(codes) > 0 {
return codes
}
codes, _ := i18nProviders.ParseLanguageCode("en,zh-CN;q=0.9,zh;q=0.8,en-US;q=0.7,en-GB;q=0.6")
......
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package httpserver_test
import (
"context"
"testing"
i18nProviders "github.com/erda-project/erda-infra/providers/i18n"
"github.com/erda-project/erda/pkg/http/httpserver"
)
func TestUnwrapI18nCodes(t *testing.T) {
codes := httpserver.UnwrapI18nCodes(context.Background())
if len(codes) == 0 {
t.Fatal("there should be codes")
}
t.Log(codes)
var lang struct{ Lang string }
codes, _ = i18nProviders.ParseLanguageCode("en,zh-CN;q=0.9,zh;q=0.8,en-US;q=0.7,en-GB;q=0.6")
ctx := context.WithValue(context.Background(), lang, codes)
codes = httpserver.UnwrapI18nCodes(ctx)
t.Log(len(codes))
if len(codes) == 0 {
t.Fatal("there should be codes")
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment