Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
fullpipe committed Oct 30, 2024
1 parent e3b06fc commit ae28173
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ bundle, err := mf.NewBundle(
mf.WithLangFallback(language.BritishEnglish, language.English),
mf.WithLangFallback(language.Portuguese, language.Spanish),

// Load all yaml files in directory as messages
mf.WithYamlProvider(messagesDir),

// or you could use your own custom message provider
// mf.WithProvider(sqlMessageProvider),

// We assume that the translated messages are mostly correct.
// However, if any errors occur during translation,
Expand All @@ -77,12 +82,6 @@ bundle, err := mf.NewBundle(
}),
)

if err != nil {
log.Fatal(err)
}

// Load all yaml files in directory as messages
err = bundle.LoadDir(messagesDir)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -131,6 +130,8 @@ func main() {
mf.WithLangFallback(language.BritishEnglish, language.English),
mf.WithLangFallback(language.Portuguese, language.Spanish),

mf.WithYamlProvider(messagesDir),

mf.WithErrorHandler(func(err error, id string, ctx map[string]any) {
slog.Error(err.Error(), slog.String("id", id), slog.Any("ctx", ctx))
}),
Expand All @@ -140,11 +141,6 @@ func main() {
log.Fatal(err)
}

err = bundle.LoadDir(messagesDir)
if err != nil {
log.Fatal(err)
}

tr := bundle.Translator("es")

slog.Info(tr.Trans("say_hello", mf.Arg("name", "Bob")))
Expand Down

0 comments on commit ae28173

Please sign in to comment.