2023-06-19 14:42:47 -07:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-11-19 21:10:04 -08:00
|
|
|
|
2023-08-10 19:46:45 -07:00
|
|
|
package errors // import "miniflux.app/v2/internal/errors"
|
2017-11-19 21:10:04 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-11-20 14:35:11 -08:00
|
|
|
|
2023-08-10 19:46:45 -07:00
|
|
|
"miniflux.app/v2/internal/locale"
|
2017-11-19 21:10:04 -08:00
|
|
|
)
|
|
|
|
|
2017-11-20 14:35:11 -08:00
|
|
|
// LocalizedError represents an error than could be translated to another language.
|
2017-11-19 21:10:04 -08:00
|
|
|
type LocalizedError struct {
|
|
|
|
message string
|
|
|
|
args []interface{}
|
|
|
|
}
|
|
|
|
|
2017-11-20 14:35:11 -08:00
|
|
|
// Error returns untranslated error message.
|
2017-11-19 21:10:04 -08:00
|
|
|
func (l LocalizedError) Error() string {
|
|
|
|
return fmt.Sprintf(l.message, l.args...)
|
|
|
|
}
|
|
|
|
|
2017-11-20 14:35:11 -08:00
|
|
|
// Localize returns the translated error message.
|
2018-09-22 15:04:55 -07:00
|
|
|
func (l LocalizedError) Localize(printer *locale.Printer) string {
|
|
|
|
return printer.Printf(l.message, l.args...)
|
2017-11-19 21:10:04 -08:00
|
|
|
}
|
|
|
|
|
2017-11-20 14:35:11 -08:00
|
|
|
// NewLocalizedError returns a new LocalizedError.
|
2018-02-27 21:08:32 -08:00
|
|
|
func NewLocalizedError(message string, args ...interface{}) *LocalizedError {
|
|
|
|
return &LocalizedError{message: message, args: args}
|
2017-11-19 21:10:04 -08:00
|
|
|
}
|