iris/middleware/i18n
Gerasimos (Makis) Maropoulos 244a59e055 20 days of unstoppable work. Waiting fo go 1.8, I didn't finish yet, some touches remains.
Former-commit-id: ed84f99c89f43fe5e980a8e6d0ee22c186f0e1b9
2017-02-14 05:54:11 +02:00
..
_example 20 days of unstoppable work. Waiting fo go 1.8, I didn't finish yet, some touches remains. 2017-02-14 05:54:11 +02:00
config.go 20 days of unstoppable work. Waiting fo go 1.8, I didn't finish yet, some touches remains. 2017-02-14 05:54:11 +02:00
i18n.go 20 days of unstoppable work. Waiting fo go 1.8, I didn't finish yet, some touches remains. 2017-02-14 05:54:11 +02:00
LICENSE 20 days of unstoppable work. Waiting fo go 1.8, I didn't finish yet, some touches remains. 2017-02-14 05:54:11 +02:00
README.md 20 days of unstoppable work. Waiting fo go 1.8, I didn't finish yet, some touches remains. 2017-02-14 05:54:11 +02:00

Middleware information

This folder contains a middleware for internationalization uses a third-party package named i81n.

More can be found here: https://github.com/Unknwon/i18n

Install

$ go get -u github.com/iris-contrib/middleware/i18n

Description

Package i18n is for app Internationalization and Localization.

How to use

Create folder named 'locales'

///Files:

./locales/locale_en-US.ini
./locales/locale_el-US.ini

Contents on locale_en-US:

hi = hello, %s

Contents on locale_el-GR:

hi = <20><><EFBFBD><EFBFBD>, %s

package main

import (
	"github.com/kataras/iris"
	"github.com/iris-contrib/middleware/i18n"
)

func main() {

	iris.UseFunc(i18n.New(i18n.Config{Default: "en-US",
		Languages: map[string]string{
			"en-US": "./locales/locale_en-US.ini",
			"el-GR": "./locales/locale_el-GR.ini",
			"zh-CN": "./locales/locale_zh-CN.ini"}}))
	// or iris.Use(i18n.I18nHandler(....))
	// or iris.Get("/",i18n.I18n(....), func (ctx *iris.Context){})

	iris.Get("/", func(ctx *iris.Context) {
		hi := ctx.GetFmt("translate")("hi", "maki") // hi is the key, 'maki' is the %s, the second parameter is optional
		language := ctx.Get("language") // language is the language key, example 'en-US'

		ctx.Write("From the language %s translated output: %s", language, hi)
	})

	iris.Listen(":8080")

}

For a working example, click here