yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/cloudprovider/i18n.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package cloudprovider
    16  
    17  import (
    18  	"yunion.io/x/onecloud/pkg/i18n"
    19  )
    20  
    21  type SModelI18nEntry struct {
    22  	Value     string
    23  	valueI18n map[i18n.Tag]string
    24  }
    25  
    26  func NewSModelI18nEntry(value string) *SModelI18nEntry {
    27  	vn := make(map[i18n.Tag]string, 0)
    28  	return &SModelI18nEntry{Value: value, valueI18n: vn}
    29  }
    30  
    31  func (self *SModelI18nEntry) GetKeyValue() string {
    32  	return self.Value
    33  }
    34  
    35  func (self *SModelI18nEntry) Lookup(tag i18n.Tag) string {
    36  	if v, ok := self.valueI18n[tag]; ok {
    37  		return v
    38  	}
    39  
    40  	return self.Value
    41  }
    42  
    43  func (self *SModelI18nEntry) CN(v string) *SModelI18nEntry {
    44  	self.valueI18n[i18n.I18N_TAG_CHINESE] = v
    45  	return self
    46  }
    47  
    48  func (self *SModelI18nEntry) EN(v string) *SModelI18nEntry {
    49  	self.valueI18n[i18n.I18N_TAG_ENGLISH] = v
    50  	return self
    51  }
    52  
    53  type SModelI18nTable map[string]*SModelI18nEntry