@@ -24,42 +24,30 @@ type Translator interface {
2424 // adds a normal translation for a particular language/locale
2525 // {#} is the only replacement type accepted and are add infintium
2626 // eg. one: '{0} day left' other: '{0} days left'
27- Add (key interface {}, text string ) error
28-
29- // is the same as Add only it allows existing translations to be overridden
30- Overwrite (key interface {}, text string ) error
27+ Add (key interface {}, text string , override bool ) error
3128
3229 // adds a cardinal plural translation for a particular language/locale
3330 // {0} is the only replacement type accepted and only one variable is accepted as
3431 // multiple cannot be used for a plural rule determination, unless it is a range;
3532 // see AddRange below.
3633 // eg. in locale 'en' one: '{0} day left' other: '{0} days left'
37- AddCardinal (key interface {}, text string , rule locales.PluralRule ) error
38-
39- // is the same as AddCardinal only it allows existing translations to be overridden
40- OverwriteCardinal (key interface {}, text string , rule locales.PluralRule ) error
34+ AddCardinal (key interface {}, text string , rule locales.PluralRule , override bool ) error
4135
4236 // adds an ordinal plural translation for a particular language/locale
4337 // {0} is the only replacement type accepted and only one variable is accepted as
4438 // multiple cannot be used for a plural rule determination, unless it is a range;
4539 // see AddRange below.
4640 // eg. in locale 'en' one: '{0}st day of spring' other: '{0}nd day of spring'
4741 // - 1st, 2nd, 3rd...
48- AddOrdinal (key interface {}, text string , rule locales.PluralRule ) error
49-
50- // is the same as AddOrdinal only it allows for existing translations to be overridden
51- OverwriteOrdinal (key interface {}, text string , rule locales.PluralRule ) error
42+ AddOrdinal (key interface {}, text string , rule locales.PluralRule , override bool ) error
5243
5344 // adds a range plural translation for a particular language/locale
5445 // {0} and {1} are the only replacement types accepted and only these are accepted.
5546 // eg. in locale 'nl' one: '{0}-{1} day left' other: '{0}-{1} days left'
56- AddRange (key interface {}, text string , rule locales.PluralRule ) error
57-
58- // is the same as AddRange only allows an existing translation to be overridden
59- OverwriteRange (key interface {}, text string , rule locales.PluralRule ) error
47+ AddRange (key interface {}, text string , rule locales.PluralRule , override bool ) error
6048
6149 // creates the translation for the locale given the 'key' and params passed in
62- T (key interface {}, params ... string ) string
50+ T (key interface {}, params ... string ) ( string , error )
6351
6452 // creates the cardinal translation for the locale given the 'key', 'num' and 'digit' arguments
6553 // and param passed in
@@ -107,18 +95,9 @@ func newTranslator(trans locales.Translator) Translator {
10795// Add adds a normal translation for a particular language/locale
10896// {#} is the only replacement type accepted and are add infintium
10997// eg. one: '{0} day left' other: '{0} days left'
110- func (t * translator ) Add (key interface {}, text string ) error {
111- return t .add (key , text , false )
112- }
98+ func (t * translator ) Add (key interface {}, text string , override bool ) error {
11399
114- // Overwrite is the same as Add only it allows existing translations to be overridden
115- func (t * translator ) Overwrite (key interface {}, text string ) error {
116- return t .add (key , text , true )
117- }
118-
119- func (t * translator ) add (key interface {}, text string , overwrite bool ) error {
120-
121- if _ , ok := t .translations [key ]; ok && ! overwrite {
100+ if _ , ok := t .translations [key ]; ok && ! override {
122101 return & ErrConflictingTranslation {key : key , text : text }
123102 }
124103
@@ -154,21 +133,12 @@ func (t *translator) add(key interface{}, text string, overwrite bool) error {
154133// multiple cannot be used for a plural rule determination, unless it is a range;
155134// see AddRange below.
156135// eg. in locale 'en' one: '{0} day left' other: '{0} days left'
157- func (t * translator ) AddCardinal (key interface {}, text string , rule locales.PluralRule ) error {
158- return t .addCardinal (key , text , rule , false )
159- }
160-
161- // OverwriteCardinal is the same as AddCardinal only it allows existing translations to be overridden
162- func (t * translator ) OverwriteCardinal (key interface {}, text string , rule locales.PluralRule ) error {
163- return t .addCardinal (key , text , rule , true )
164- }
165-
166- func (t * translator ) addCardinal (key interface {}, text string , rule locales.PluralRule , overwrite bool ) error {
136+ func (t * translator ) AddCardinal (key interface {}, text string , rule locales.PluralRule , override bool ) error {
167137
168138 tarr , ok := t .cardinalTanslations [key ]
169139 if ok {
170140 // verify not adding a conflicting record
171- if len (tarr ) > 0 && tarr [rule ] != nil && ! overwrite {
141+ if len (tarr ) > 0 && tarr [rule ] != nil && ! override {
172142 return & ErrConflictingTranslation {key : key , rule : rule , text : text }
173143 }
174144
@@ -201,21 +171,12 @@ func (t *translator) addCardinal(key interface{}, text string, rule locales.Plur
201171// multiple cannot be used for a plural rule determination, unless it is a range;
202172// see AddRange below.
203173// eg. in locale 'en' one: '{0}st day of spring' other: '{0}nd day of spring' - 1st, 2nd, 3rd...
204- func (t * translator ) AddOrdinal (key interface {}, text string , rule locales.PluralRule ) error {
205- return t .addOrdinal (key , text , rule , false )
206- }
207-
208- // OverwriteOrdinal is the same as AddOrdinal only it allows for existing translations to be overridden
209- func (t * translator ) OverwriteOrdinal (key interface {}, text string , rule locales.PluralRule ) error {
210- return t .addOrdinal (key , text , rule , true )
211- }
212-
213- func (t * translator ) addOrdinal (key interface {}, text string , rule locales.PluralRule , overwrite bool ) error {
174+ func (t * translator ) AddOrdinal (key interface {}, text string , rule locales.PluralRule , override bool ) error {
214175
215176 tarr , ok := t .ordinalTanslations [key ]
216177 if ok {
217178 // verify not adding a conflicting record
218- if len (tarr ) > 0 && tarr [rule ] != nil && ! overwrite {
179+ if len (tarr ) > 0 && tarr [rule ] != nil && ! override {
219180 return & ErrConflictingTranslation {key : key , rule : rule , text : text }
220181 }
221182
@@ -246,21 +207,12 @@ func (t *translator) addOrdinal(key interface{}, text string, rule locales.Plura
246207// AddRange adds a range plural translation for a particular language/locale
247208// {0} and {1} are the only replacement types accepted and only these are accepted.
248209// eg. in locale 'nl' one: '{0}-{1} day left' other: '{0}-{1} days left'
249- func (t * translator ) AddRange (key interface {}, text string , rule locales.PluralRule ) error {
250- return t .addRange (key , text , rule , false )
251- }
252-
253- // OverwriteRange is the same as AddRange only allows an existing translation to be overridden
254- func (t * translator ) OverwriteRange (key interface {}, text string , rule locales.PluralRule ) error {
255- return t .addRange (key , text , rule , true )
256- }
257-
258- func (t * translator ) addRange (key interface {}, text string , rule locales.PluralRule , overwrite bool ) error {
210+ func (t * translator ) AddRange (key interface {}, text string , rule locales.PluralRule , override bool ) error {
259211
260212 tarr , ok := t .rangeTanslations [key ]
261213 if ok {
262214 // verify not adding a conflicting record
263- if len (tarr ) > 0 && tarr [rule ] != nil && ! overwrite {
215+ if len (tarr ) > 0 && tarr [rule ] != nil && ! override {
264216 return & ErrConflictingTranslation {key : key , rule : rule , text : text }
265217 }
266218
@@ -298,11 +250,11 @@ func (t *translator) addRange(key interface{}, text string, rule locales.PluralR
298250}
299251
300252// T creates the translation for the locale given the 'key' and params passed in
301- func (t * translator ) T (key interface {}, params ... string ) string {
253+ func (t * translator ) T (key interface {}, params ... string ) ( string , error ) {
302254
303255 trans , ok := t .translations [key ]
304256 if ! ok {
305- return unknownTranslation
257+ return unknownTranslation , ErrUnknowTranslation
306258 }
307259
308260 b := make ([]byte , 0 , 64 )
@@ -320,7 +272,7 @@ func (t *translator) T(key interface{}, params ...string) string {
320272
321273 b = append (b , trans .text [start :]... )
322274
323- return string (b )
275+ return string (b ), nil
324276}
325277
326278// C creates the cardinal translation for the locale given the 'key', 'num' and 'digit' arguments and param passed in
0 commit comments