Skip to content

address.cityPrefix returning undefined on pt_BR #623

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

Closed
ponei opened this issue Mar 16, 2022 · 12 comments
Closed

address.cityPrefix returning undefined on pt_BR #623

ponei opened this issue Mar 16, 2022 · 12 comments
Labels
c: bug Something isn't working c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs has workaround Workaround provided or linked p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug

Comments

@ponei
Copy link

ponei commented Mar 16, 2022

Describe the bug

Title pretty much sums it up. This is dependent on locale and doesn't happen on english - did not test on other locales other than pt_BR and en.

Reproduction

Calling address.cityPrefix or any other function that uses it (address.city sometimes does) returns undefined

Additional Info

No response

@Shinigami92
Copy link
Member

https://github.com/faker-js/faker/blob/main/src/locales/pt_BR/address/city_prefix.ts

There is a city_prefix, but it is empty 🤔

Was this also the case with v5.5.3?

I will look into this after I fully woke up.

@Shinigami92 Shinigami92 added the c: bug Something isn't working label Mar 16, 2022
@Shinigami92 Shinigami92 moved this to Todo in Faker Roadmap Mar 16, 2022
@ST-DDT
Copy link
Member

ST-DDT commented Mar 16, 2022

@ST-DDT ST-DDT added this to the v6.1 - First bugfixes milestone Mar 16, 2022
@ST-DDT ST-DDT added p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug labels Mar 16, 2022
@ST-DDT
Copy link
Member

ST-DDT commented Mar 16, 2022

@ponei Are you fluent/familiar with pt_br?
If yes, could you create a PR that adds some common city prefixes?

@Shinigami92
Copy link
Member

The only question I have right now is: was it different in v5.5.3, then it could be a || => ?? change somewhere or something like that. So maybe we accidentally changed behavior somewhere.

@ST-DDT
Copy link
Member

ST-DDT commented Mar 16, 2022

The only question I have right now is: was it different in v5.5.3, then it could be a || => ?? change somewhere or something like that. So maybe we accidentally changed behavior somewhere.

This doesn't have any impact. An empty array wouldn't get replaced either way.

@Shinigami92
Copy link
Member

We have a somewhat related PR for the general issue: #609

But adding some city prefixes for pt_BR would definitely be nice anyway

@ST-DDT
Copy link
Member

ST-DDT commented Mar 16, 2022

Maybe add/fix citySuffix as well?

@ponei
Copy link
Author

ponei commented Mar 16, 2022

@ponei Are you fluent/familiar with pt_br?
If yes, could you create a PR that adds some common city prefixes?

Yes, I'm fluent with portuguese. I could come up with some after work, but prefixes for cities aren't very common here, suffixes are.
In english you would have something like West {cityName} but that doesn't translate really well.
Regions/other adjectives are suffixes because that's how they work in portuguese, so you would have something like {cityName} do Sul (south region).

Maybe the locale should say what it prefers? (suffix or prefix). Then if you want to override you could pass arguments explicitly saying otherwise.

@ST-DDT
Copy link
Member

ST-DDT commented Mar 16, 2022

Yeah the generator patterns should be in the locale definitions as well (v6.2 or later).

Maybe add '' as prefix for now, that way you don't get undefined in those texts anymore.
The extra space in the city names is hopefully negligible.

@srjheam
Copy link

srjheam commented Mar 17, 2022

Maybe add/fix citySuffix as well?

There are no city prefixes/suffixes in pt_BR. Is there a way to return only address.cityName?

@Shinigami92
Copy link
Member

For now please call faker.fake('{{address.cityName}}') as a workaround.

I looked into the implementation of

faker/src/address.ts

Lines 95 to 112 in 2b934c5

city(format?: string | number): string {
const formats = [
'{{address.cityPrefix}} {{name.firstName}}{{address.citySuffix}}',
'{{address.cityPrefix}} {{name.firstName}}',
'{{name.firstName}}{{address.citySuffix}}',
'{{name.lastName}}{{address.citySuffix}}',
];
if (!format && this.faker.definitions.address.city_name) {
formats.push('{{address.cityName}}');
}
if (typeof format !== 'number') {
format = this.faker.datatype.number(formats.length - 1);
}
return f(formats[format]);
}

and damn, this is a mess 🤣
We need to fully rework this implementation, but this will be a breaking change. So I will move this to v7, because there is a workaround for now.

@Shinigami92 Shinigami92 added has workaround Workaround provided or linked c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs labels Mar 17, 2022
@ST-DDT
Copy link
Member

ST-DDT commented Jun 8, 2022

Now there is faker.address.cityName() and faker.address.city() uses a localized pattern (not sure whether its correct though).
If its not correct, please open a PR and provide us with the correct one.

'{{address.cityPrefix}} {{name.firstName}}{{address.citySuffix}}',
'{{address.cityPrefix}} {{name.firstName}}',
'{{name.firstName}}{{address.citySuffix}}',
'{{name.lastName}}{{address.citySuffix}}',

The cityPrefix and suffix methods itself will be deprecated for removal in #1041 .

@ST-DDT ST-DDT closed this as completed Jun 8, 2022
Repository owner moved this from Todo to Done in Faker Roadmap Jun 8, 2022
@ST-DDT ST-DDT removed this from Faker Roadmap Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs has workaround Workaround provided or linked p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
Development

No branches or pull requests

4 participants