i18n.go 1.1 KB

1234567891011121314151617181920212223242526272829
  1. package context
  2. import "golang.org/x/text/language"
  3. // I18nReadOnly is the interface which contains the read-only i18n features.
  4. // Read the "i18n" package fo details.
  5. type I18nReadOnly interface {
  6. Tags() []language.Tag
  7. GetLocale(ctx *Context) Locale
  8. Tr(lang string, key string, args ...interface{}) string
  9. TrContext(ctx *Context, key string, args ...interface{}) string
  10. }
  11. // Locale is the interface which returns from a `Localizer.GetLocale` method.
  12. // It serves the translations based on "key" or format. See `GetMessage`.
  13. type Locale interface {
  14. // Index returns the current locale index from the languages list.
  15. Index() int
  16. // Tag returns the full language Tag attached to this Locale,
  17. // it should be unique across different Locales.
  18. Tag() *language.Tag
  19. // Language should return the exact languagecode of this `Locale`
  20. //that the user provided on `New` function.
  21. //
  22. // Same as `Tag().String()` but it's static.
  23. Language() string
  24. // GetMessage should return translated text based on the given "key".
  25. GetMessage(key string, args ...interface{}) string
  26. }