@@ -2,6 +2,7 @@ package i18n
22
33import (
44 "path/filepath"
5+ "embed"
56 "strings"
67 "golang.org/x/text/language"
78 "encoding/json"
@@ -12,6 +13,9 @@ import (
1213 // "github.ibm.com/SoftLayer/softlayer-cli/plugin/resources"
1314)
1415
16+ //go:embed resources/*.json
17+ var LocaleFS embed.FS
18+
1519const (
1620 DEFAULT_LOCALE = "en_US"
1721)
@@ -73,8 +77,8 @@ func T(text string, subs ...interface{}) string {
7377func Init () * goi18n.Localizer {
7478 bundle := goi18n .NewBundle (language .English )
7579 bundle .RegisterUnmarshalFunc ("json" , json .Unmarshal )
76- bundle .MustLoadMessageFile ( "plugin/i18n/ resources/en_US.json" )
77- bundle .MustLoadMessageFile ( "plugin/i18n/ resources/ja_JP.json" )
80+ bundle .LoadMessageFileFS ( LocaleFS , " resources/en_US.json" )
81+ bundle .LoadMessageFileFS ( LocaleFS , " resources/ja_JP.json" )
7882 loc := goi18n .NewLocalizer (bundle , "ja_JP" )
7983 return loc
8084}
@@ -83,9 +87,9 @@ func Init() *goi18n.Localizer {
8387func InitWithLocale (locale string ) {
8488 bundle := goi18n .NewBundle (language .English )
8589 bundle .RegisterUnmarshalFunc ("json" , json .Unmarshal )
86- bundle .MustLoadMessageFile ( "plugin/i18n/ resources/en_US.json" )
90+ bundle .LoadMessageFileFS ( LocaleFS , " resources/en_US.json" )
8791 if locale != "en_US" {
88- bundle .MustLoadMessageFile ( fmt .Sprintf ("plugin/i18n/ resources/%s.json" , locale ))
92+ bundle .LoadMessageFileFS ( LocaleFS , fmt .Sprintf ("resources/%s.json" , locale ))
8993 }
9094 loc := goi18n .NewLocalizer (bundle , locale )
9195 localizer = loc
0 commit comments