miniflux/errors/errors.go

33 lines
894 B
Go
Raw Normal View History

2017-11-20 06:10:04 +01:00
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
2018-08-25 06:51:50 +02:00
package errors // import "miniflux.app/errors"
2017-11-20 06:10:04 +01:00
import (
"fmt"
2017-11-20 23:35:11 +01:00
2018-08-25 06:51:50 +02:00
"miniflux.app/locale"
2017-11-20 06:10:04 +01:00
)
2017-11-20 23:35:11 +01:00
// LocalizedError represents an error than could be translated to another language.
2017-11-20 06:10:04 +01:00
type LocalizedError struct {
message string
args []interface{}
}
2017-11-20 23:35:11 +01:00
// Error returns untranslated error message.
2017-11-20 06:10:04 +01:00
func (l LocalizedError) Error() string {
return fmt.Sprintf(l.message, l.args...)
}
2017-11-20 23:35:11 +01:00
// Localize returns the translated error message.
func (l LocalizedError) Localize(printer *locale.Printer) string {
return printer.Printf(l.message, l.args...)
2017-11-20 06:10:04 +01:00
}
2017-11-20 23:35:11 +01:00
// NewLocalizedError returns a new LocalizedError.
func NewLocalizedError(message string, args ...interface{}) *LocalizedError {
return &LocalizedError{message: message, args: args}
2017-11-20 06:10:04 +01:00
}