i18n

GitHub Workflow Status Codecov GoDoc Sourcegraph

Package i18n is a middleware that provides internationalization and localization for Flamego.

Installation

The minimum requirement of Go is 1.16.

  1. go get github.com/flamego/i18n

Getting started

  1. # locales/locale_en-US.ini
  2. greeting = How are you?
  1. # locales/locale_zh-CN.ini
  2. greeting = 你好吗?
  1. package main
  2. import (
  3. "github.com/flamego/flamego"
  4. "github.com/flamego/i18n"
  5. )
  6. func main() {
  7. f := flamego.Classic()
  8. f.Use(i18n.I18n(
  9. i18n.Options{
  10. Languages: []i18n.Language{
  11. {Name: "en-US", Description: "English"},
  12. {Name: "zh-CN", Description: "简体中文"},
  13. },
  14. },
  15. ))
  16. f.Get("/", func(l i18n.Locale) {
  17. message := l.Translate("greeting")
  18. // ...
  19. })
  20. f.Run()
  21. }

Getting help

License

This project is under the MIT License. See the LICENSE file for the full license text.