package module
Version: v0.6.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2020 License: Apache-2.0 Imports: 9 Imported by: 399



GitHub Workflow Status codecov GoDoc Sourcegraph

Package i18n provides an Internationalization and Localization middleware for Macaron applications.

go get github.com/go-macaron/i18n

Getting Help


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



Package i18n provides an Internationalization and Localization middleware for Macaron applications.



This section is empty.


This section is empty.


func I18n

func I18n(options ...Options) macaron.Handler

I18n is a middleware provides localization layer for your application. Paramenter langs must be in the form of "en-US", "zh-CN", etc. Otherwise it may not recognize browser input.


type LangType

type LangType struct {
	Lang, Name string

type Locale

type Locale struct {

A Locale describles the information of localization.

func (Locale) Language

func (l Locale) Language() string

Language returns language current locale represents.

type Options

type Options struct {
	// Suburl of path. Default is empty.
	SubURL string
	// Directory to load locale files. Default is "conf/locale"
	Directory string
	// File stores actual data of locale files. Used for in-memory purpose.
	Files map[string][]byte
	// Custom directory to overload locale files. Default is "custom/conf/locale"
	CustomDirectory string
	// Langauges that will be supported, order is meaningful.
	Langs []string
	// Human friendly names corresponding to Langs list.
	Names []string
	// Default language locale, leave empty to remain unset.
	DefaultLang string
	// Locale file naming style. Default is "locale_%s.ini".
	Format string
	// Name of language parameter name in URL. Default is "lang".
	Parameter string
	// Redirect when user uses get parameter to specify language.
	Redirect bool
	// Name that maps into template variable. Default is "i18n".
	TmplName string
	// Configuration section name. Default is "i18n".
	Section string
	// Domain used for `lang` cookie. Default is ""
	CookieDomain string
	// Set the Secure flag on the `lang` cookie. Default is disabled.
	Secure bool
	// Set the HTTP Only flag on the `lang` cookie. Default is disabled.
	CookieHttpOnly bool
	// Set the SameSite flag on the `lang` cookie. Default is unset.
	SameSite http.SameSite

Options represents a struct for specifying configuration options for the i18n middleware.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL