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

faker.location.state() not working for sk #3052

Closed
8 of 10 tasks
boubkerbribri opened this issue Aug 13, 2024 · 12 comments · Fixed by #3054
Closed
8 of 10 tasks

faker.location.state() not working for sk #3052

boubkerbribri opened this issue Aug 13, 2024 · 12 comments · Fixed by #3054
Assignees
Labels
c: locale Permutes locale definitions m: location Something is referring to the location module p: 1-normal Nothing urgent
Milestone

Comments

@boubkerbribri
Copy link
Contributor

boubkerbribri commented Aug 13, 2024

Pre-Checks

Describe the bug

I'm trying to get faker.local.state() for local sk with a local fallback en_US, but I keep getting this error [Error]: The locale data for 'location.state' aren't applicable to this locale.

Minimal reproduction code

const {sk, Faker, en_US} = require('@faker-js/faker')

const faker = new Faker({locale: [sk, en_US]})
console.log(faker.location.state())

Additional Context

image

Environment Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 291.94 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.16.0/bin/yarn
    npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
  Browsers:
    Chrome: 127.0.6533.100
    Safari: 17.5
  npmPackages:
    @faker-js/faker: 8.4.1 => 8.4.1

Which module system do you use?

  • CJS
  • ESM

Used Package Manager

npm

@boubkerbribri boubkerbribri added c: bug Something isn't working s: pending triage Pending Triage labels Aug 13, 2024
@Shinigami92
Copy link
Member

@Shinigami92 Shinigami92 added c: locale Permutes locale definitions m: location Something is referring to the location module and removed c: bug Something isn't working s: pending triage Pending Triage labels Aug 13, 2024
@Shinigami92 Shinigami92 added this to the vAnytime milestone Aug 13, 2024
@ST-DDT ST-DDT added the p: 1-normal Nothing urgent label Aug 13, 2024
@boubkerbribri
Copy link
Contributor Author

boubkerbribri commented Aug 13, 2024

Yeah of course, I can contribute to that but I need to understand well the behavior.

On Documentation, it says In this example there are 5 locales. Each of these is checked in order, and the first locale which contains the requested data will be used
So when I try to get state for this faker const faker = new Faker({locale: [sk, en_US]}) I expect to get one for en_US.

I think I'm missing something, if you could point that out please ?

@Shinigami92
Copy link
Member

I think I'm missing something, if you could point that out please?

Sure, just read the comment above that linked to the other PR. We introduced a specific null for some special cases so you wont get US states while using the sk locale.
states are a bit more realistically faked and so the intention is that you will get provided with states that are in that specific locale.
Additionally we added this behavior for exactly such a case right now, where a user comes up and found a locale that is not fully completed yet. And then we can kindly ask these contributors to help us, because a person like you are trained in sk locale, where as the internal maintainer team is mostly just german 😄

@ST-DDT
Copy link
Member

ST-DDT commented Aug 13, 2024

The null means that sk doesn't have states/states aren't applicable to sk (or at least, that's what our data say).
null data are considered as "we have data here", but there is no valid way to fill them. (Similar to how there aren't any states on mars, there are likely also states that don't have separate countries)
It is likely wrong data in this case.

https://en.wikipedia.org/wiki/Slovakia#Administrative_divisions

Currently, en_US is missing the state definitions as well, en_US uses the fallback to en to provide these data which happen to be en_US, but en really should be either absent or cover more locales. So your fallback doesn't help in this case.

Since explicit "non-applicable" wins over any later fallbacks you have to adjust the order accordingly.

import { sk, Faker, en } from '@faker-js/faker';

const faker = new Faker({
  locale: [{ location: { state: en.location.state } }, sk],
});
console.log(faker.location.state());

On Documentation, it says In this example there are 5 locales. Each of these is checked in order, and the first locale which contains the requested data will be used

It looks like we have to clarify this some more.

I think we additionally have to add a sections that explicitly explains what to do when you get the missing or non applicable data errors.

@xDivisionByZerox

This comment was marked as duplicate.

@xDivisionByZerox
Copy link
Member

I created #3053 to enhance the documentation. This issue can focus on aligning the locale data for sk.

@boubkerbribri
Copy link
Contributor Author

Thank you all for your explanations.
I'm more than happy to contribute but I should tell that I'm not an expert on SK locales.
I was just trying to generate an address for more than 15 locals with the same function, sometimes I use state, sometimes I don't. That's why I used the fallback actually. but doesn't work that why so I understand.

@matthewmayer
Copy link
Contributor

Note you probably want to just use fakerSK rather than using the constructor. That automatically will use sk, en-us and en in order.

@matthewmayer
Copy link
Contributor

Note you probably want to just use fakerSK rather than using the constructor. That automatically will use sk, en-us and en in order.

actually that won't work since the SK states are null, rather than omitted. i think Faker is incorrect about that - null should only be used where we know that data is not applicable - e.g. https://github.com/faker-js/faker/blob/next/src/locales/en_HK/location/postcode.ts is null because Hong Kong doesn't have postcodes. Slovakia does have first-level administrative regions, it's just they havent been filled in yet.

@ST-DDT
Copy link
Member

ST-DDT commented Aug 13, 2024

@boubkerbribri I tried adding some documentation for these errors:

Does that help you? Is it easy to understand? Is something missing?

@ST-DDT ST-DDT changed the title Locale fallback not working using sk faker.local.state() not working for sk Aug 13, 2024
@ST-DDT ST-DDT linked a pull request Aug 13, 2024 that will close this issue
@boubkerbribri
Copy link
Contributor Author

@boubkerbribri I tried adding some documentation for these errors:

Does that help you? Is it easy to understand? Is somethign missing?

Yes, I think it's clear and understandable, it's what you said on the comment with more examples.
And the example works fine.
Thanks

@ST-DDT ST-DDT changed the title faker.local.state() not working for sk faker.location.state() not working for sk Aug 13, 2024
@matthewmayer
Copy link
Contributor

Part of #1977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: locale Permutes locale definitions m: location Something is referring to the location module p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants