Determining The Current Locale

You may use the context.GetLocale method to determine the current locale or check if the locale is a given value:

  1. func(ctx iris.Context) {
  2. locale := ctx.GetLocale()
  3. // [...]
  4. }

The Locale interface looks like this.

  1. // Locale is the interface which returns from a `Localizer.GetLocale` metod.
  2. // It serves the transltions based on "key" or format. See `GetMessage`.
  3. type Locale interface {
  4. // Index returns the current locale index from the languages list.
  5. Index() int
  6. // Tag returns the full language Tag attached tothis Locale,
  7. // it should be uniue across different Locales.
  8. Tag() *language.Tag
  9. // Language should return the exact languagecode of this `Locale`
  10. //that the user provided on `New` function.
  11. //
  12. // Same as `Tag().String()` but it's static.
  13. Language() string
  14. // GetMessage should return translated text based n the given "key".
  15. GetMessage(key string, args ...interface{}) string
  16. }