errors.go 652 B

123456789101112131415161718192021222324252627
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package errors
  5. import (
  6. "fmt"
  7. "github.com/miniflux/miniflux2/locale"
  8. )
  9. type LocalizedError struct {
  10. message string
  11. args []interface{}
  12. }
  13. func (l LocalizedError) Error() string {
  14. return fmt.Sprintf(l.message, l.args...)
  15. }
  16. func (l LocalizedError) Localize(translation *locale.Language) string {
  17. return translation.Get(l.message, l.args...)
  18. }
  19. func NewLocalizedError(message string, args ...interface{}) LocalizedError {
  20. return LocalizedError{message: message, args: args}
  21. }