Skip to content

Commit

Permalink
existing language detection reimplemented
Browse files Browse the repository at this point in the history
  • Loading branch information
icrowley committed Dec 23, 2014
1 parent 170d5bc commit 64a824f
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 27 deletions.
14 changes: 11 additions & 3 deletions fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@ var r = rand.New(rand.NewSource(time.Now().UnixNano()))
var lang = "en"
var useExternalData = false
var enFallback = false
var availLangs = GetLangs()

var (
ErrInsufficientParams = fmt.Errorf("Insufficient params to lookup the samples")
ErrNoLanguageFn = func(lang string) error { return fmt.Errorf("The language passed (%s) is not available", lang) }
ErrNoSamplesFn = func(lang string) error { return fmt.Errorf("No samples found for language: %s", lang) }
)

func SetLang(newLang string) error {
availLangs := []string{"en", "br", "ca", "da", "de", "fi", "fr", "mx", "nl", "se", "sn", "uk", "us", "ja", "ar", "cn", "cs",
"ga", "it", "kr", "nb", "ph", "th", "vn"}
func GetLangs() []string {
var langs []string
for k, v := range data {
if v.isDir && k != "/" && k != "/data" {
langs = append(langs, strings.Replace(k, "/data", "", 1))
}
}
return langs
}

func SetLang(newLang string) error {
found := false
for _, l := range availLangs {
if newLang == l {
Expand Down
3 changes: 1 addition & 2 deletions test/addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestAddresses(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.Continent()
Expand Down
3 changes: 1 addition & 2 deletions test/credit_cards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestCreditCards(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.CreditCardType()
Expand Down
3 changes: 1 addition & 2 deletions test/currencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestCurrencies(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.Currency()
Expand Down
3 changes: 1 addition & 2 deletions test/dates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
)

func TestDates(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.WeekDay()
Expand Down
3 changes: 1 addition & 2 deletions test/general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestGeneral(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.Password(4, 10, true, true, true)
Expand Down
3 changes: 1 addition & 2 deletions test/geo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestGeo(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

f := fake.Latitute()
Expand Down
3 changes: 1 addition & 2 deletions test/internet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestInternet(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.UserName()
Expand Down
3 changes: 1 addition & 2 deletions test/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestJobs(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.Company()
Expand Down
3 changes: 1 addition & 2 deletions test/lorem_ipsum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestLoremIpsum(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.Character()
Expand Down
3 changes: 1 addition & 2 deletions test/names_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestNames(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.MaleFirstName()
Expand Down
3 changes: 1 addition & 2 deletions test/personal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestPersonal(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.Gender()
Expand Down
3 changes: 1 addition & 2 deletions test/products_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestProducts(t *testing.T) {
langs := []string{"en", "ru"}
for _, lang := range langs {
for _, lang := range fake.GetLangs() {
fake.SetLang(lang)

v := fake.Brand()
Expand Down

0 comments on commit 64a824f

Please sign in to comment.