Skip to content

Commit 432f72c

Browse files
Dean KarnDean Karn
authored andcommitted
correct small bug double wrapping locales.Translator + added GetFallback() method.
1 parent 6b05665 commit 432f72c

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## universal-translator
22
<img align="right" src="https://raw.githubusercontent.com/go-playground/universal-translator/master/logo.png">
3-
![Project status](https://img.shields.io/badge/version-0.11.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-0.12.0-green.svg)
44
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/universal-translator/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/universal-translator)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/universal-translator/badge.svg)](https://coveralls.io/github/go-playground/universal-translator)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/universal-translator)](https://goreportcard.com/report/github.com/go-playground/universal-translator)

translator_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,20 @@ func TestVerifyTranslations(t *testing.T) {
688688
t.Fatalf("Expected '<nil>' Got '%s'", err)
689689
}
690690
}
691+
692+
func TestGetFallback(t *testing.T) {
693+
694+
// dutch
695+
n := nl.New()
696+
e := en.New()
697+
698+
uni := New(e, n)
699+
700+
trans := uni.GetFallback()
701+
702+
expected := "en"
703+
704+
if trans.Locale() != expected {
705+
t.Errorf("Expected '%s' Got '%s'", expected, trans.Locale())
706+
}
707+
}

universal-translator.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func New(fallback locales.Translator, supportedLocales ...locales.Translator) *U
2323
for _, v := range supportedLocales {
2424

2525
trans := newTranslator(v)
26-
t.translators[strings.ToLower(trans.Locale())] = newTranslator(trans)
26+
t.translators[strings.ToLower(trans.Locale())] = trans
2727

2828
if fallback.Locale() == v.Locale() {
2929
t.fallback = trans
@@ -65,6 +65,11 @@ func (t *UniversalTranslator) GetTranslator(locale string) Translator {
6565
return t.fallback
6666
}
6767

68+
// GetFallback returns the fallback locale
69+
func (t *UniversalTranslator) GetFallback() Translator {
70+
return t.fallback
71+
}
72+
6873
// AddTranslator adds the supplied translator, if it already exists the override param
6974
// will be checked and if false an error will be returned, otherwise the translator will be
7075
// overridden; if the fallback matches the supplied translator it will be overridden as well

0 commit comments

Comments
 (0)