i18n.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. package cloudprovider
  15. import (
  16. "golang.org/x/text/language"
  17. )
  18. type SModelI18nEntry struct {
  19. Value string
  20. valueI18n map[language.Tag]string
  21. }
  22. func NewSModelI18nEntry(value string) *SModelI18nEntry {
  23. vn := make(map[language.Tag]string, 0)
  24. return &SModelI18nEntry{Value: value, valueI18n: vn}
  25. }
  26. func (entry *SModelI18nEntry) GetKeyValue() string {
  27. return entry.Value
  28. }
  29. func (entry *SModelI18nEntry) Lookup(tag language.Tag) string {
  30. if v, ok := entry.valueI18n[tag]; ok {
  31. return v
  32. }
  33. return entry.Value
  34. }
  35. func (entry *SModelI18nEntry) CN(v string) *SModelI18nEntry {
  36. entry.valueI18n[language.Chinese] = v
  37. return entry
  38. }
  39. func (entry *SModelI18nEntry) EN(v string) *SModelI18nEntry {
  40. entry.valueI18n[language.English] = v
  41. return entry
  42. }
  43. type SModelI18nTable map[string]*SModelI18nEntry