errors.go 871 B

12345678910111213141516171819202122232425262728293031
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package errors // import "miniflux.app/v2/internal/errors"
  4. import (
  5. "fmt"
  6. "miniflux.app/v2/internal/locale"
  7. )
  8. // LocalizedError represents an error than could be translated to another language.
  9. type LocalizedError struct {
  10. message string
  11. args []interface{}
  12. }
  13. // Error returns untranslated error message.
  14. func (l LocalizedError) Error() string {
  15. return fmt.Sprintf(l.message, l.args...)
  16. }
  17. // Localize returns the translated error message.
  18. func (l LocalizedError) Localize(printer *locale.Printer) string {
  19. return printer.Printf(l.message, l.args...)
  20. }
  21. // NewLocalizedError returns a new LocalizedError.
  22. func NewLocalizedError(message string, args ...interface{}) *LocalizedError {
  23. return &LocalizedError{message: message, args: args}
  24. }