https://github.com/kamikazechaser/locale
Simple locale template rendering using KV maps only
https://github.com/kamikazechaser/locale
i10n i18n internationalization localization translation
Last synced: 8 months ago
JSON representation
Simple locale template rendering using KV maps only
- Host: GitHub
- URL: https://github.com/kamikazechaser/locale
- Owner: kamikazechaser
- License: unlicense
- Created: 2023-06-26T05:54:05.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-01-25T09:36:36.000Z (over 2 years ago)
- Last Synced: 2025-07-25T00:58:00.068Z (11 months ago)
- Topics: i10n, i18n, internationalization, localization, translation
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# locale
> Simple locale template rendering using KV maps only
[](https://pkg.go.dev/github.com/kamikazechaser/locale)
Provides a _simple_ and _flexible_ way to render your translations. You are not locked into any i18n/i10n standard.
## Install:
`go get github.com/kamikazechaser/locale`
## Example
```go
package main
import (
"log"
"github.com/kamikazechaser/locale"
)
func main() {
lMap := locale.LangMap{
"eng": locale.Map{
"hello": "Hello {{ .Name }}",
},
"swa": locale.Map{
"hello": "Habari {{ .Name }}",
},
}
l, err := locale.NewLocale(lMap, "eng")
if err != nil {
log.Fatal(err)
}
payload := struct {
Name string
}{
"Mohamed Sohail",
}
// Will use the default language here.
eR, err := l.Render("hello", locale.WithPayload(payload))
if err != nil {
log.Fatal(err)
}
// Using all available Render optional function options.
sR, err := l.Render("hello", locale.WithLangCode("swa"), locale.WithPayload(payload))
if err != nil {
log.Fatal(err)
}
log.Println(eR)
log.Println(sR)
}
```
For more info, See the Go package reference.
## License
The Unlicense.
## Credits
- Some of the API inspired by https://github.com/kataras/i18n