Skip to content

Commit 0982988

Browse files
using embed for json files
1 parent 1f75f3b commit 0982988

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

plugin/i18n/i18n.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package i18n
22

33
import (
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+
1519
const (
1620
DEFAULT_LOCALE = "en_US"
1721
)
@@ -73,8 +77,8 @@ func T(text string, subs ...interface{}) string {
7377
func 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 {
8387
func 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

Comments
 (0)