bxcodec / faker

Go (Golang) Fake Data Generator for Struct. [Notes]This repository is archived, moved to the new repository https://github.com/go-faker/faker
https://pkg.go.dev/github.com/bxcodec/faker/v4
MIT License
2.09k stars 148 forks source link

Is localization supported? #120

Open frederikhors opened 4 years ago

frederikhors commented 4 years ago

I don't understand if languages (localization, l18n) is supported.

E.g.: can I generate fake french first names?

bxcodec commented 4 years ago

Maybe you can take a look here for the example https://github.com/bxcodec/faker/blob/master/example_with_tags_lang_test.go

frederikhors commented 4 years ago

I saw that. But I cannot make it work.

E.g., I need french names. I'm trying with this code:

package main

import (
  "fmt"
  "github.com/bxcodec/faker/v3"
)

type SomeStructWithTags struct {
  FirstName       string `faker:"first_name lang=fre"`
  FirstNameMale   string `faker:"first_name_male lang=fre"`
  FirstNameFemale string `faker:"first_name_female lang=fre"`
  LastName        string `faker:"last_name lang=fre"`
}

func main() {
  a := SomeStructWithTags{}

  err := faker.FakeData(&a)
  if err != nil {
    println(err)
  }

  fmt.Printf("%+v", a)
}

It prints this:

{FirstName:PMawBtnvaCdgaLvlfuJlPeEWC FirstNameMale:WgxIlLkCJveRsoiblYCCnmauo FirstNameFemale:rilfCEbQUhpdyYpiOMwbkLqDl LastName:tZMFqPivpXktdQLUikuQmhsRl}

Am I wrong?

djk29a commented 3 years ago

The only three languages supported with the code so far looks to be English, Chinese, and Russian. A "language" is defined with a rune range including exceptions and an informal language spec label. To support French additional characters would need to be added with a new language spec similar to the built-ins https://github.com/bxcodec/faker/blob/7460bf3a84de3afbfe7297c488c711d29f09c5d2/faker.go#L56-L63

Support for ISO 639-1 or IETF locales such as en, fr-TN or fr is thus not present.