lang

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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) 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.

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.

/en/products
/fr/produits
...

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:

en-UK
  ├─ 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") and, if needed, the default language provided in the config. This function is intended for internal use only.

Types

This section is empty.

Jump to

Keyboard shortcuts

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