Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Is localization supported? #120

Open
frederikhors opened this issue Sep 15, 2020 · 3 comments
Open

Is localization supported? #120

frederikhors opened this issue Sep 15, 2020 · 3 comments

Comments

@frederikhors
Copy link

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

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

@bxcodec
Copy link
Owner

bxcodec commented Oct 9, 2020

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

@frederikhors
Copy link
Author

frederikhors commented Oct 9, 2020

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
Copy link

djk29a commented Sep 30, 2021

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

faker/faker.go

Lines 56 to 63 in 7460bf3

var (
// LangENG is for english language
LangENG = langRuneBoundary{65, 122, []rune{91, 92, 93, 94, 95, 96}}
// LangCHI is for chinese language
LangCHI = langRuneBoundary{19968, 40869, nil}
// LangRUS is for russian language
LangRUS = langRuneBoundary{1025, 1105, nil}
)

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants