@@ -3,11 +3,13 @@ package i18n
33import (
44 "path/filepath"
55 "strings"
6-
7- "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/configuration/core_config"
6+ "golang.org/x/text/language"
7+ "encoding/json"
8+ "fmt"
9+ // "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/configuration/core_config"
810 "github.com/Xuanwo/go-locale"
9- goi18n "github.com/nicksnyder/go-i18n/i18n"
10- "github.ibm.com/SoftLayer/softlayer-cli/plugin/resources"
11+ goi18n "github.com/nicksnyder/go-i18n/v2/ i18n"
12+ // "github.ibm.com/SoftLayer/softlayer-cli/plugin/resources"
1113)
1214
1315const (
@@ -28,6 +30,7 @@ var SUPPORTED_LOCALES = []string{
2830}
2931
3032var resourcePath = filepath .Join ("plugin" , "i18n" , "resources" )
33+ var localizer = Init ()
3134
3235func GetResourcePath () string {
3336 return resourcePath
@@ -37,14 +40,34 @@ func SetResourcePath(path string) {
3740 resourcePath = path
3841}
3942
40- var T goi18n.TranslateFunc = Init (core_config .NewCoreConfig (func (error ) {}))
43+ // var T goi18n.TranslateFunc = Init(core_config.NewCoreConfig(func(error) {}))
44+
45+ func T (text string , subs ... interface {}) string {
46+
47+ // fmt.Printf("SUBS: %v\n", subs)
48+ message := & goi18n.Message {ID : text , Other : text }
49+ config := & goi18n.LocalizeConfig {DefaultMessage : message }
50+ l_string , err := localizer .Localize (config )
51+ if err != nil {
52+ fmt .Printf ("ERROR i18n\n " )
53+ return err .Error ()
54+ }
55+ return l_string
56+ }
57+
58+
4159
42- func Init (coreConfig core_config.Repository ) goi18n.TranslateFunc {
43- userLocale := coreConfig .Locale ()
44- locale := supportedLocale (userLocale )
45- return initWithLocale (locale )
60+
61+ func Init () * goi18n.Localizer {
62+ bundle := goi18n .NewBundle (language .English )
63+ bundle .RegisterUnmarshalFunc ("json" , json .Unmarshal )
64+ bundle .MustLoadMessageFile ("plugin/i18n/resources/en_US.json" )
65+ bundle .MustLoadMessageFile ("plugin/i18n/resources/ja_JP.json" )
66+ loc := goi18n .NewLocalizer (bundle , language .English .String ())
67+ return loc
4668}
4769
70+ /*
4871func initWithLocale(locale string) goi18n.TranslateFunc {
4972 err := loadFromAsset(locale)
5073 if err != nil {
@@ -64,6 +87,7 @@ func loadFromAsset(locale string) (err error) {
6487 return
6588}
6689
90+ */
6791// Tries to determine the system locale, when local isn't set, default to en_US
6892func DetectLocal () string {
6993 tag , err := locale .Detect ()
@@ -75,6 +99,7 @@ func DetectLocal() string {
7599 return locale
76100}
77101
102+
78103// Tries to match the system locale with a supported locale, otherwise sets a DEFAULT_LOCALE
79104func supportedLocale (configLocal string ) string {
80105
0 commit comments