7 "github.com/go-playground/locales"
11 // ErrUnknowTranslation indicates the translation could not be found
12 ErrUnknowTranslation = errors.New("Unknown Translation")
15 var _ error = new(ErrConflictingTranslation)
16 var _ error = new(ErrRangeTranslation)
17 var _ error = new(ErrOrdinalTranslation)
18 var _ error = new(ErrCardinalTranslation)
19 var _ error = new(ErrMissingPluralTranslation)
20 var _ error = new(ErrExistingTranslator)
22 // ErrExistingTranslator is the error representing a conflicting translator
23 type ErrExistingTranslator struct {
27 // Error returns ErrExistingTranslator's internal error text
28 func (e *ErrExistingTranslator) Error() string {
29 return fmt.Sprintf("error: conflicting translator for locale '%s'", e.locale)
32 // ErrConflictingTranslation is the error representing a conflicting translation
33 type ErrConflictingTranslation struct {
36 rule locales.PluralRule
40 // Error returns ErrConflictingTranslation's internal error text
41 func (e *ErrConflictingTranslation) Error() string {
43 if _, ok := e.key.(string); !ok {
44 return fmt.Sprintf("error: conflicting key '%#v' rule '%s' with text '%s' for locale '%s', value being ignored", e.key, e.rule, e.text, e.locale)
47 return fmt.Sprintf("error: conflicting key '%s' rule '%s' with text '%s' for locale '%s', value being ignored", e.key, e.rule, e.text, e.locale)
50 // ErrRangeTranslation is the error representing a range translation error
51 type ErrRangeTranslation struct {
55 // Error returns ErrRangeTranslation's internal error text
56 func (e *ErrRangeTranslation) Error() string {
60 // ErrOrdinalTranslation is the error representing an ordinal translation error
61 type ErrOrdinalTranslation struct {
65 // Error returns ErrOrdinalTranslation's internal error text
66 func (e *ErrOrdinalTranslation) Error() string {
70 // ErrCardinalTranslation is the error representing a cardinal translation error
71 type ErrCardinalTranslation struct {
75 // Error returns ErrCardinalTranslation's internal error text
76 func (e *ErrCardinalTranslation) Error() string {
80 // ErrMissingPluralTranslation is the error signifying a missing translation given
81 // the locales plural rules.
82 type ErrMissingPluralTranslation struct {
85 rule locales.PluralRule
86 translationType string
89 // Error returns ErrMissingPluralTranslation's internal error text
90 func (e *ErrMissingPluralTranslation) Error() string {
92 if _, ok := e.key.(string); !ok {
93 return fmt.Sprintf("error: missing '%s' plural rule '%s' for translation with key '%#v' and locale '%s'", e.translationType, e.rule, e.key, e.locale)
96 return fmt.Sprintf("error: missing '%s' plural rule '%s' for translation with key '%s' and locale '%s'", e.translationType, e.rule, e.key, e.locale)
99 // ErrMissingBracket is the error representing a missing bracket in a translation
100 // eg. This is a {0 <-- missing ending '}'
101 type ErrMissingBracket struct {
107 // Error returns ErrMissingBracket error message
108 func (e *ErrMissingBracket) Error() string {
109 return fmt.Sprintf("error: missing bracket '{}', in translation. locale: '%s' key: '%v' text: '%s'", e.locale, e.key, e.text)
112 // ErrBadParamSyntax is the error representing a bad parameter definition in a translation
113 // eg. This is a {must-be-int}
114 type ErrBadParamSyntax struct {
121 // Error returns ErrBadParamSyntax error message
122 func (e *ErrBadParamSyntax) Error() string {
123 return fmt.Sprintf("error: bad parameter syntax, missing parameter '%s' in translation. locale: '%s' key: '%v' text: '%s'", e.param, e.locale, e.key, e.text)
126 // import/export errors
128 // ErrMissingLocale is the error representing an expected locale that could
129 // not be found aka locale not registered with the UniversalTranslator Instance
130 type ErrMissingLocale struct {
134 // Error returns ErrMissingLocale's internal error text
135 func (e *ErrMissingLocale) Error() string {
136 return fmt.Sprintf("error: locale '%s' not registered.", e.locale)
139 // ErrBadPluralDefinition is the error representing an incorrect plural definition
140 // usually found within translations defined within files during the import process.
141 type ErrBadPluralDefinition struct {
145 // Error returns ErrBadPluralDefinition's internal error text
146 func (e *ErrBadPluralDefinition) Error() string {
147 return fmt.Sprintf("error: bad plural definition '%#v'", e.tl)