...
1 package ut
2
3 import (
4 "errors"
5 "fmt"
6
7 "github.com/go-playground/locales"
8 )
9
10 var (
11
12 ErrUnknowTranslation = errors.New("Unknown Translation")
13 )
14
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)
21
22
23 type ErrExistingTranslator struct {
24 locale string
25 }
26
27
28 func (e *ErrExistingTranslator) Error() string {
29 return fmt.Sprintf("error: conflicting translator for locale '%s'", e.locale)
30 }
31
32
33 type ErrConflictingTranslation struct {
34 locale string
35 key interface{}
36 rule locales.PluralRule
37 text string
38 }
39
40
41 func (e *ErrConflictingTranslation) Error() string {
42
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)
45 }
46
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)
48 }
49
50
51 type ErrRangeTranslation struct {
52 text string
53 }
54
55
56 func (e *ErrRangeTranslation) Error() string {
57 return e.text
58 }
59
60
61 type ErrOrdinalTranslation struct {
62 text string
63 }
64
65
66 func (e *ErrOrdinalTranslation) Error() string {
67 return e.text
68 }
69
70
71 type ErrCardinalTranslation struct {
72 text string
73 }
74
75
76 func (e *ErrCardinalTranslation) Error() string {
77 return e.text
78 }
79
80
81
82 type ErrMissingPluralTranslation struct {
83 locale string
84 key interface{}
85 rule locales.PluralRule
86 translationType string
87 }
88
89
90 func (e *ErrMissingPluralTranslation) Error() string {
91
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)
94 }
95
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)
97 }
98
99
100
101 type ErrMissingBracket struct {
102 locale string
103 key interface{}
104 text string
105 }
106
107
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)
110 }
111
112
113
114 type ErrBadParamSyntax struct {
115 locale string
116 param string
117 key interface{}
118 text string
119 }
120
121
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)
124 }
125
126
127
128
129
130 type ErrMissingLocale struct {
131 locale string
132 }
133
134
135 func (e *ErrMissingLocale) Error() string {
136 return fmt.Sprintf("error: locale '%s' not registered.", e.locale)
137 }
138
139
140
141 type ErrBadPluralDefinition struct {
142 tl translation
143 }
144
145
146 func (e *ErrBadPluralDefinition) Error() string {
147 return fmt.Sprintf("error: bad plural definition '%#v'", e.tl)
148 }
149
View as plain text