Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address.country_code does not consider locale (I18n) #2684

Closed
ghost opened this issue Jan 17, 2023 · 3 comments
Closed

Address.country_code does not consider locale (I18n) #2684

ghost opened this issue Jan 17, 2023 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 17, 2023

Describe the bug

if locale is set, then Address.country_code does not consider it, but e.g. street/city/... do.

To Reproduce

irb(main):006:0> I18n.locale = 'da-DK'
=> "da-DK"
irb(main):009:0> Faker::Address.country_code
=> "CR"
irb(main):010:0> Faker::Address.city
=> "Jydelund"

Expected behavior

that the country_code act the same way?!

Additional context

I used the country code to define a fake address and recognized with that change (3.1.0), that country_code does not consider the locale but don't know, if it makes sense here or not?!

@ghost ghost added the 🐞 Issue: Bug label Jan 17, 2023
@stefannibrasil
Copy link
Contributor

HI @PhiliGor thanks for reporting the bug.

The cities and other address values make sense to change depending of the locale, but not the country_code and country_code_long. I believe Address.country_code behavior did not take into consideration the locales.

All locales should use the en/address.yml for both country_codes and country_code_long. So the locale should default to those keys because we want country_code to return a list of country codes following the ISO country code country codes, regardless of the locale. More context here. This country code is used for fetching a country by code, and we want them to return random ISO values.

If the behavior that we want is that, when setting a locale, Faker generates the country code of the given locale, the key for fetching that value would be default_country_code: ["IN"].

Two locales files already have that:

default_country_code: ["IN"]

and

default_country_code: ["NP"]

The locales are files that haven't had too much help, unfortunately, including the docs. So it's understandable it causes confusion. Opening bug reports like this is helpful to improve them.

To fix this issue, we would need to set the default_country_code to all locales. For example, for the locale en-DK, we need another key: default_country_code: ["DK"], and that's what you would use to fetch the locale's country code.

Also, the locale docs would need to be updated so this is better documented for other users.

Are you interested in opening a PR to add the default_country_code to the locales that don't have it?

@ashwin-elangovan
Copy link
Contributor

Hi @stefannibrasil

I have raised a PR #2732 where default_country_code is added to other locales. Can you kindly take a look at it?

@stefannibrasil
Copy link
Contributor

thank you @ashwin-elangovan !

Closed by #2732

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

No branches or pull requests

2 participants