This section is empty.


This section is empty.


func DetectLanguage

func DetectLanguage(lang string) string

DetectLanguage detects the language to use based on the given lang string. The given lang string can use the HTTP "Accept-Language" header format.

If "*" is provided, the default language will be used. If multiple languages are given, the first available language will be used, and if none are available, the default language will be used. If no variant is given (for example "en"), the first available variant will be used. For example, if "en-US" and "en-UK" are available and the request accepts "en", "en-US" will be used.

func Get

func Get(lang string, line string, placeholders ...string) string

Get a language line.

For validation rules and attributes messages, use a dot-separated path: - "validation.rules.<rule_name>" - "validation.fields.<field_name>" - "validation.fields.<field_name>.<rule_name>" For normal lines, just use the name of the line. Note that if you have a line called "validation", it won't conflict with the dot-separated paths.

If not found, returns the exact "line" attribute.

The placeholders parameter is a variadic associative slice of placeholders and their replacement. In the following example, the placeholder ":username" will be replaced with the Name field in the user struct.

lang.Get("en-US", "greetings", ":username", user.Name)

func GetAvailableLanguages

func GetAvailableLanguages() []string

GetAvailableLanguages returns a slice of all loaded languages. This can be used to generate different routes for all languages supported by your applications.


func IsAvailable

func IsAvailable(lang string) bool

IsAvailable returns true if the language is available.

func Load

func Load(language, path string)

Load a language directory.

Directory structure of a language directory:

  ├─ locale.json     (contains the normal language lines)
  ├─ rules.json      (contains the validation messages)
  └─ attributes.json (contains the attribute-specific validation messages)

Each file is optional.

func LoadAllAvailableLanguages

func LoadAllAvailableLanguages()

LoadAllAvailableLanguages loads every language directory in the "resources/lang" directory if it exists.

func LoadDefault

func LoadDefault()

LoadDefault load the fallback language ("en-US"). This function is intended for internal use only.


This section is empty.