Skip to content

Commit

Permalink
correct small bug double wrapping locales.Translator + added GetFallb…
Browse files Browse the repository at this point in the history
…ack() method.
  • Loading branch information
Dean Karn authored and Dean Karn committed Sep 1, 2016
1 parent 6b05665 commit 432f72c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## universal-translator
<img align="right" src="https://raw.githubusercontent.com/go-playground/universal-translator/master/logo.png">
![Project status](https://img.shields.io/badge/version-0.11.0-green.svg)
![Project status](https://img.shields.io/badge/version-0.12.0-green.svg)
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/universal-translator/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/universal-translator)
[![Coverage Status](https://coveralls.io/repos/github/go-playground/universal-translator/badge.svg)](https://coveralls.io/github/go-playground/universal-translator)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/universal-translator)](https://goreportcard.com/report/github.com/go-playground/universal-translator)
Expand Down
17 changes: 17 additions & 0 deletions translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,3 +688,20 @@ func TestVerifyTranslations(t *testing.T) {
t.Fatalf("Expected '<nil>' Got '%s'", err)
}
}

func TestGetFallback(t *testing.T) {

// dutch
n := nl.New()
e := en.New()

uni := New(e, n)

trans := uni.GetFallback()

expected := "en"

if trans.Locale() != expected {
t.Errorf("Expected '%s' Got '%s'", expected, trans.Locale())
}
}
7 changes: 6 additions & 1 deletion universal-translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func New(fallback locales.Translator, supportedLocales ...locales.Translator) *U
for _, v := range supportedLocales {

trans := newTranslator(v)
t.translators[strings.ToLower(trans.Locale())] = newTranslator(trans)
t.translators[strings.ToLower(trans.Locale())] = trans

if fallback.Locale() == v.Locale() {
t.fallback = trans
Expand Down Expand Up @@ -65,6 +65,11 @@ func (t *UniversalTranslator) GetTranslator(locale string) Translator {
return t.fallback
}

// GetFallback returns the fallback locale
func (t *UniversalTranslator) GetFallback() Translator {
return t.fallback
}

// AddTranslator adds the supplied translator, if it already exists the override param
// will be checked and if false an error will be returned, otherwise the translator will be
// overridden; if the fallback matches the supplied translator it will be overridden as well
Expand Down

0 comments on commit 432f72c

Please sign in to comment.