mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix: use i18n.Table to handle Chinese-English conversion
This commit is contained in:
@@ -60,9 +60,6 @@ const (
|
||||
|
||||
ZSTACK_BRAND_DSTACK = "DStack"
|
||||
ONECLOUD_BRAND_ONECLOUD = "OneCloud"
|
||||
|
||||
CLOUD_PROVIDER_ONECLOUD_EN = "YunionCloud"
|
||||
CLOUD_PROVIDER_ONECLOUD_CN = "云联壹云"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
33
pkg/apis/compute/consts_i18n.go
Normal file
33
pkg/apis/compute/consts_i18n.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// 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 compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/i18n"
|
||||
)
|
||||
|
||||
const (
|
||||
CLOUD_PROVIDER_ONECLOUD_EN = "YunionCloud"
|
||||
CLOUD_PROVIDER_ONECLOUD_CN = "云联壹云"
|
||||
)
|
||||
|
||||
var ComputeI18nTable = i18n.Table{}
|
||||
|
||||
func init() {
|
||||
ComputeI18nTable.Set(CLOUD_PROVIDER_ONECLOUD, i18n.NewTableEntry().
|
||||
EN(CLOUD_PROVIDER_ONECLOUD_EN).
|
||||
CN(CLOUD_PROVIDER_ONECLOUD_CN),
|
||||
)
|
||||
}
|
||||
@@ -24,8 +24,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
@@ -46,24 +44,24 @@ var (
|
||||
|
||||
notifyAdminUsers []string
|
||||
notifyAdminGroups []string
|
||||
|
||||
notifyclientI18nTable = i18n.Table{}
|
||||
)
|
||||
|
||||
const (
|
||||
SUFFIX = "suffix"
|
||||
)
|
||||
|
||||
func init() {
|
||||
notifyClientWorkerMan = appsrv.NewWorkerManager("NotifyClientWorkerManager", 1, 50, false)
|
||||
templatesTableLock = &sync.Mutex{}
|
||||
templatesTable = make(map[string]*template.Template)
|
||||
|
||||
notifyclientI18nTable.Set(SUFFIX, i18n.NewTableEntry().EN("en").CN("cn"))
|
||||
}
|
||||
|
||||
func getLangSuffix(ctx context.Context) string {
|
||||
lang := i18n.Lang(ctx)
|
||||
switch lang {
|
||||
case language.English:
|
||||
return "en"
|
||||
case language.Chinese:
|
||||
return "cn"
|
||||
default:
|
||||
return "en"
|
||||
}
|
||||
return notifyclientI18nTable.Lookup(ctx, SUFFIX)
|
||||
}
|
||||
|
||||
func getTemplateString(ctx context.Context, topic string, contType string, channel npk.TNotifyChannel) ([]byte, error) {
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
"gopkg.in/fatih/set.v0"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -54,7 +53,6 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/i18n"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
@@ -840,12 +838,7 @@ func (self *SGuest) NotifyServerEvent(
|
||||
if host != nil {
|
||||
brand := host.GetBrand()
|
||||
if brand == api.CLOUD_PROVIDER_ONECLOUD {
|
||||
switch i18n.Lang(ctx) {
|
||||
case language.Chinese:
|
||||
brand = api.CLOUD_PROVIDER_ONECLOUD_CN
|
||||
default:
|
||||
brand = api.CLOUD_PROVIDER_ONECLOUD_EN
|
||||
}
|
||||
brand = api.ComputeI18nTable.Lookup(ctx, brand)
|
||||
}
|
||||
kwargs.Add(jsonutils.NewString(brand), "brand")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user