errors.go 882 B

1234567891011121314151617181920212223242526272829303132
  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/miniflux/locale"
  8. )
  9. // LocalizedError represents an error than could be translated to another language.
  10. type LocalizedError struct {
  11. message string
  12. args []interface{}
  13. }
  14. // Error returns untranslated error message.
  15. func (l LocalizedError) Error() string {
  16. return fmt.Sprintf(l.message, l.args...)
  17. }
  18. // Localize returns the translated error message.
  19. func (l LocalizedError) Localize(translation *locale.Language) string {
  20. return translation.Get(l.message, l.args...)
  21. }
  22. // NewLocalizedError returns a new LocalizedError.
  23. func NewLocalizedError(message string, args ...interface{}) LocalizedError {
  24. return LocalizedError{message: message, args: args}
  25. }