feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> * feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> --------- Signed-off-by: ci-bot <ci-bot@kubesphere.io> Co-authored-by: ks-ci-bot <ks-ci-bot@example.com> Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
committed by
GitHub
parent
b5015ec7b9
commit
447a51f08b
67
vendor/k8s.io/kubectl/pkg/util/i18n/i18n.go
generated
vendored
67
vendor/k8s.io/kubectl/pkg/util/i18n/i18n.go
generated
vendored
@@ -24,8 +24,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/chai2010/gettext-go"
|
||||
|
||||
gettext "github.com/chai2010/gettext-go"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
@@ -52,6 +54,56 @@ var knownTranslations = map[string][]string{
|
||||
},
|
||||
}
|
||||
|
||||
var (
|
||||
lazyLoadTranslationsOnce sync.Once
|
||||
LoadTranslationsFunc = func() error {
|
||||
return LoadTranslations("kubectl", nil)
|
||||
}
|
||||
translationsLoaded bool
|
||||
)
|
||||
|
||||
// SetLoadTranslationsFunc sets the function called to lazy load translations.
|
||||
// It must be called in an init() func that occurs BEFORE any i18n.T() calls are made by any package. You can
|
||||
// accomplish this by creating a separate package containing your init() func, and then importing that package BEFORE
|
||||
// any other packages that call i18n.T().
|
||||
//
|
||||
// Example Usage:
|
||||
//
|
||||
// package myi18n
|
||||
//
|
||||
// import "k8s.io/kubectl/pkg/util/i18n"
|
||||
//
|
||||
// func init() {
|
||||
// if err := i18n.SetLoadTranslationsFunc(loadCustomTranslations); err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func loadCustomTranslations() error {
|
||||
// // Load your custom translations here...
|
||||
// }
|
||||
//
|
||||
// And then in your main or root command package, import your custom package like this:
|
||||
//
|
||||
// import (
|
||||
// // Other imports that don't need i18n...
|
||||
// _ "example.com/myapp/myi18n"
|
||||
// // Other imports that do need i18n...
|
||||
// )
|
||||
func SetLoadTranslationsFunc(f func() error) error {
|
||||
if translationsLoaded {
|
||||
return errors.New("translations have already been loaded")
|
||||
}
|
||||
LoadTranslationsFunc = func() error {
|
||||
if err := f(); err != nil {
|
||||
return err
|
||||
}
|
||||
translationsLoaded = true
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadSystemLanguage() string {
|
||||
// Implements the following locale priority order: LC_ALL, LC_MESSAGES, LANG
|
||||
// Similarly to: https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html
|
||||
@@ -128,13 +180,26 @@ func LoadTranslations(root string, getLanguageFn func() string) error {
|
||||
gettext.BindLocale(gettext.New("k8s", root+".zip", buf.Bytes()))
|
||||
gettext.SetDomain("k8s")
|
||||
gettext.SetLanguage(langStr)
|
||||
translationsLoaded = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func lazyLoadTranslations() {
|
||||
lazyLoadTranslationsOnce.Do(func() {
|
||||
if translationsLoaded {
|
||||
return
|
||||
}
|
||||
if err := LoadTranslationsFunc(); err != nil {
|
||||
klog.Warning("Failed to load translations")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// T translates a string, possibly substituting arguments into it along
|
||||
// the way. If len(args) is > 0, args1 is assumed to be the plural value
|
||||
// and plural translation is used.
|
||||
func T(defaultValue string, args ...int) string {
|
||||
lazyLoadTranslations()
|
||||
if len(args) == 0 {
|
||||
return gettext.PGettext("", defaultValue)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user