Skip to content

Package i18n is a middleware that provides app Internationalization and Localization of Macross.

License

Notifications You must be signed in to change notification settings

macross-contrib/i18n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

i18n

Middleware i18n provides app Internationalization and Localization for Macross.

Installation

go get -u github.com/macross-contrib/i18n

Example

package main

import (
	"fmt"
	"github.com/insionng/macross"
	"github.com/macross-contrib/i18n"
)

func main() {
	m := macross.Classic()
	m.Use(i18n.I18n(i18n.Options{
		Directory:   "locale",
		DefaultLang: "zh-CN",
		Langs:       []string{"en-US", "zh-CN"},
		Names:       []string{"English", "简体中文"},
		Redirect:    true,
	}))

	m.Get("/", func(self *macross.Context) error {
		fmt.Println("Header>", self.Request.Header.String())
		return self.String("current language is " + self.Language())
	})

	// Use in handler.
	m.Get("/trans", func(self *macross.Context) error {
		fmt.Println("Header>", self.Request.Header.String())
		return self.String(fmt.Sprintf("hello %s", self.Tr("world")))
	})

	fmt.Println("Listen on 9999")
	m.Listen(9999)
}

Getting Help

License

This project is under the Apache License, Version 2.0. See the LICENSE file for the full license text.

About

Package i18n is a middleware that provides app Internationalization and Localization of Macross.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages