Internationalization and Localization

This is a middleware


Create folder named 'locales':

// Files:


Contents on locale_en-US:

hi = hello, %s

Contents on locale_el-GR:

hi = Γειά, %s

package main

import (

func main() {

    iris.Use(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"}}))

    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.Writef("From the language %s translated output: %s", language, hi)



results matching ""

    No results matching ""