java-faker icon indicating copy to clipboard operation
java-faker copied to clipboard

Cant generate address by Locale

Open amedvedjev opened this issue 4 years ago • 5 comments

Describe the bug I am trying to generate fake address data by country using supported locales.

To Reproduce

        Faker faker = new Faker(new Locale("en-US"));
        System.out.println(String.format("en-US: %s", faker.address().country()));
        faker = new Faker(new Locale("hu"));
        System.out.println(String.format("hu: %s", faker.address().country()));
        faker = new Faker(Locale.FRANCE);
        System.out.println(String.format("FRANCE: %s", faker.address().country()));
        faker = new Faker(Locale.UK);
        System.out.println(String.format("UK: %s", faker.address().country()));

Expected behavior Real address data per selected locale.

Result Random data.

en-US: Panama
hu: Málta
FRANCE: Kyrgyz Republic
UK: Fiji

Versions:

  • OS: macOS 10.15.3
  • JDK: 1.8.0_231-b11
  • Faker Version: 1.0.2

amedvedjev avatar Apr 28 '20 07:04 amedvedjev

Our group are interested in this issue, we will try to fix it. ---- SE_Sustech

Juan-Chen45 avatar Mar 11 '21 14:03 Juan-Chen45

Unfortunately, the way you use javafaker is wrong. France/UK are countries that don't contain other countries, even if you set these locale, faker.address.country() still return random countries. You can call faker.address.city() or faker.address.state() and the result will be right.

Jiapeng-Pei avatar Apr 17 '21 08:04 Jiapeng-Pei

I am also having the same problem

Faker.instance(new Locale("en","GB")).address().state()

returns US states not UK. The whole address is affected - It doesn't happen with other locales.

cheekymonkat avatar Aug 24 '21 15:08 cheekymonkat

Hello @amedvedjev , our group are interested in this issue, and we will try to fix it. ---- SE_SUSTech, group: Lanrand

youyumeimei avatar Mar 09 '22 18:03 youyumeimei

@youyumeimei this library is no longer maintained. An active fork is hosted at www.datafaker.net

Would you be willing to contribute there? We release a new version every month.

bodiam avatar Mar 09 '22 21:03 bodiam