From 4a8034cfab99c95772bcdcd996ab763bc1667541 Mon Sep 17 00:00:00 2001 From: alobaton Date: Thu, 15 Apr 2021 15:56:18 -0500 Subject: [PATCH] Add example --- README.md | 4 ++++ example/main.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 example/main.go diff --git a/README.md b/README.md index 4d034fe..eea80c9 100644 --- a/README.md +++ b/README.md @@ -104,3 +104,7 @@ go get github.com/alobaton/i18n ```bash $ go test i18n/... ``` + +## Example + +Here you can find an [example](https://github.com/alobaton/i18n/blob/main/example/main.go) \ No newline at end of file diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..dd52bd0 --- /dev/null +++ b/example/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + + "github.com/alobaton/i18n" +) + +var I18N *i18n.I18N + +func main() { + var err error + I18N = i18n.NewI18N().BindPath("./en.json") + I18N, err = I18N.BindMainLocale("en") + if err != nil { + panic(err) + } + + I18N, err = I18N.Init() + if err != nil { + panic(err) + } + + result, err := I18N.Lookup("some.awesome.text") + if err != nil { + panic(err) + } + + fmt.Println(result) +}