Introduction

Localization features provide a convenient way to retrieve strings in various languages, allowing you to easily support multiple languages within your application. Language strings are stored in files within the ./locales directory. Within this directory there should be a subdirectory for each language supported by the application:

  1. main.go
  2. └───locales
  3. ├───el-GR
  4. home.yml
  5. ├───en-US
  6. home.yml
  7. └───zh-CN
  8. home.yml

The default language for your application is the first registered language.

  1. app := iris.New()
  2. // First parameter: Glob filpath patern,
  3. // Second variadic parameter: Optional language tags,
  4. // the first one is the default/fallback one.
  5. app.I18n.Load("./locales/*/*", "en-US", "el-GR", "zh-CN")

Or if you load all languages by:

  1. app.I18n.Load("./locales/*/*")
  2. // Then set the default language using:
  3. app.I18n.SetDefault("en-US")