2017-11-20 00:10:04 -05: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.
|
|
|
|
|
|
|
|
package errors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-11-20 17:35:11 -05:00
|
|
|
|
2017-12-13 00:48:13 -05:00
|
|
|
"github.com/miniflux/miniflux/locale"
|
2017-11-20 00:10:04 -05:00
|
|
|
)
|
|
|
|
|
2017-11-20 17:35:11 -05:00
|
|
|
// LocalizedError represents an error than could be translated to another language.
|
2017-11-20 00:10:04 -05:00
|
|
|
type LocalizedError struct {
|
|
|
|
message string
|
|
|
|
args []interface{}
|
|
|
|
}
|
|
|
|
|
2017-11-20 17:35:11 -05:00
|
|
|
// Error returns untranslated error message.
|
2017-11-20 00:10:04 -05:00
|
|
|
func (l LocalizedError) Error() string {
|
|
|
|
return fmt.Sprintf(l.message, l.args...)
|
|
|
|
}
|
|
|
|
|
2017-11-20 17:35:11 -05:00
|
|
|
// Localize returns the translated error message.
|
2017-11-20 00:10:04 -05:00
|
|
|
func (l LocalizedError) Localize(translation *locale.Language) string {
|
|
|
|
return translation.Get(l.message, l.args...)
|
|
|
|
}
|
|
|
|
|
2017-11-20 17:35:11 -05:00
|
|
|
// NewLocalizedError returns a new LocalizedError.
|
2018-02-28 00:08:32 -05:00
|
|
|
func NewLocalizedError(message string, args ...interface{}) *LocalizedError {
|
|
|
|
return &LocalizedError{message: message, args: args}
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|