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

feat: use street address templates from locales #754

Merged
merged 7 commits into from
Apr 5, 2022

Conversation

ST-DDT
Copy link
Member

@ST-DDT ST-DDT commented Apr 2, 2022

Adds #88

  • Adds faker.address.buildingNumber()
  • Rewrite faker.address.streetAddress() to use the templates from the locales
  • Update locale template files to the fake() format

@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug labels Apr 2, 2022
@ST-DDT ST-DDT added this to the v6.2 - New small features milestone Apr 2, 2022
@ST-DDT ST-DDT self-assigned this Apr 2, 2022
@ST-DDT ST-DDT linked an issue Apr 2, 2022 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Apr 2, 2022

Codecov Report

Merging #754 (799a8f1) into main (6a2d8fc) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 799a8f1 differs from pull request most recent head 46515f7. Consider uploading reports for the commit 46515f7 to get more accurate results

@@           Coverage Diff           @@
##             main     #754   +/-   ##
=======================================
  Coverage   99.34%   99.34%           
=======================================
  Files        1921     1921           
  Lines      176540   176628   +88     
  Branches      908      906    -2     
=======================================
+ Hits       175387   175475   +88     
  Misses       1097     1097           
  Partials       56       56           
Impacted Files Coverage Δ
src/address.ts 99.81% <100.00%> (-0.01%) ⬇️
src/definitions/address.ts 100.00% <100.00%> (ø)
src/locales/ar/address/street_address.ts 100.00% <100.00%> (ø)
src/locales/az/address/street_address.ts 100.00% <100.00%> (ø)
src/locales/cz/address/street_address.ts 100.00% <100.00%> (ø)
src/locales/de/address/street_address.ts 100.00% <100.00%> (ø)
src/locales/de_AT/address/street_address.ts 100.00% <100.00%> (ø)
src/locales/en/address/street_address.ts 100.00% <100.00%> (ø)
src/locales/en_GH/address/street_address.ts 100.00% <100.00%> (ø)
src/locales/es/address/street_address.ts 100.00% <100.00%> (ø)
... and 28 more

@ST-DDT
Copy link
Member Author

ST-DDT commented Apr 2, 2022

Depends on #756

@ST-DDT ST-DDT added s: on hold Blocked by something or frozen to avoid conflicts and removed s: on hold Blocked by something or frozen to avoid conflicts labels Apr 2, 2022
@ST-DDT
Copy link
Member Author

ST-DDT commented Apr 2, 2022

#756 was merged

@ST-DDT
Copy link
Member Author

ST-DDT commented Apr 2, 2022

I converted the street_address templates using the following script:

function updateLocaleFileHook(
  filePath: string,
  locale: string,
  localePath: string[]
): void {
  if (localePath[0] === 'address' && localePath[1] === 'street_address') {
    console.log(filePath + ' <-> ' + locale + ' @ ' + localePath.join(' -> '));
    let content: string[] = require(filePath).default.map((entry) =>
      entry
        .replace('#{street_name}', '{{address.streetName}}')
        .replace('#{address.street_name}', '{{address.streetName}}')
        .replace('#{building_number}', '{{address.buildingNumber}}')
        .replace('#{address.building_number}', '{{address.buildingNumber}}')
        .replace('#{secondary_address}', '{{address.secondaryAddress}}')
    );
    content = [
      content[0].replace(' {{address.secondaryAddress}}', '').replace(/,$/, ''),
      content[1] ??
        content[0].replace(' {{address.secondaryAddress}}', '') +
          ' {{address.secondaryAddress}}',
    ];

    let fileContent =
      'export default ' + JSON.stringify(content) + ' as [string, string]';
    fileContent = format(fileContent, prettierTsOptions);
    console.log(fileContent);
    writeFileSync(filePath, fileContent);
  }
}

During the implementation I noticed, that some locale files contained two patterns, one with the normal pattern and one with the full pattern.
Since there seems to be a special pattern to these too, I decided to change the implementation again to use only the format from the template. I hope, I grasped to original intention behind this file correctly.

I'm not sure whether [string, string] is the best type, I also considered { normal: string; full: string }, the later might be easier to extend and does not require casting.
Which do you like the most?

@ST-DDT ST-DDT marked this pull request as ready for review April 2, 2022 22:36
@ST-DDT ST-DDT requested a review from a team as a code owner April 2, 2022 22:36
@ST-DDT ST-DDT requested a review from a team April 2, 2022 22:36
@ST-DDT
Copy link
Member Author

ST-DDT commented Apr 2, 2022

Here are some examples for the generated addresses: (click to expand)
Locale Normal Full
af_ZA 1027 Dippenaar Neck 574 Schmidt Motorway Suite 833
ar 90492 جاوحدو Oval 4506 بندر Roads 246 شقة
az Ethelyn pr., 417 King sahəsi, 739 m. 453
cz Foltýnová Lights 831 Ctibor Neck 0 Apt. 248
de Flore Pass 9 Estelle Loaf 30b Apt. 526
de_AT Ruckdeschel Centers 06 Linus Canyon 58 Zimmer 554
de_CH 7344 Schwab Burg 343 Sidler Wells Suite 718
el 1214 Στέφανος Stravenue 0082 Ελευθέριος Burg Suite 445
en 0261 Boehm Port 637 Raleigh Causeway Suite 971
en_AU 74 Moss Track 38 Matilda Terrace Apt. 165
en_AU_ocker 19 Nigel Crescent 9997 Samuel Loop Suite 283
en_BORK 5677 Eveline View 9131 Johnson Burg Suite 826
en_CA 839 Langworth Flat 3834 Walker Ville Apt. 608
en_GB 803 Denesik Wall 9847 Baumbach Valley Suite 893
en_GH 511 Asamoa Street 26 Agyare Road Apt. 225
en_IE 73197 Johanna Stream 36351 Cruickshank Flat Apt. 603
en_IND 7453 Guneta Views 0986 Gudakesha Plaza Suite 227
en_NG 948 Shalewa Squares 65637 Chukwu Harbors Apt. 708
en_US 7225 Erick Lane 712 Lakin Turnpike Suite 071
en_ZA 001 Rafael Junctions 9731 Jonathan Knolls Suite 730
es Guerrero Huerta s/n. Juan Carlos Calleja 6 Puerta 594
es_MX Arellano Partida 0 Ana Luisa Monte s/n. Edificio 1
fa علی‌پور آفریقا, پلاک 19 همایون کارگر شمالی, پلاک 36 9 طبقه
fi 4464 Nieminen Park 81229 Annikki Estates Suite 564
fr 8879 Mathieu du Chat-qui-Pêche 617 Leclerc Montorgueil Apt. 149
fr_BE Meryl de Barchon 935c Tasnim du Chat-qui-Pêche 057b Suite 780
fr_CA 875 Enola Tunnel 520 Loyce Extensions Suite 221
fr_CH 163 Augustine Via 841 Magdalena Circle Suite 115
ge ჩიხრაძე გამზირი 89 აბაშიძე ხეივანი 49 კორპ. 93
he 221 באר Lakes 785 בןגוריון Shore 45 חדר
hr Ancica Stream 2 Ada Inlet 4 Stan 71
hy Նարեկ փողոց 614/4 Գևորգ պողոտա 38 Բն. 298
id_ID Kiehn Street no 84 Madyson Spur no 18 Apt. 983
it Daciano Via 22 Alcide Rotonda 8, Appartamento 74
ja 2459 結愛 Roads 949 太一 Glens Apt. 519
ko 4750 늘찬 면 3014 준빈 읍 Apt. 210
lv Jonathon gāte 21 Javier laukums 192 - 808
mk Чаловска Mountain 3 Бужаровски Isle 068 стан 42
nb_NO Mathisen hagen 5 Leah holtet 7 Leil. 640
ne 83445 Hamal Mountain 83133 Ajita Canyon Suite 014
nl Dijk dijk 7 Berg laan 916 II 3 hoog
nl_BE Lotte park 5 Luna plein 1 3e verdieping
pl Apollinary Mews 074 Klaudiusz Plain 8730 Apt. 562
pt_BR 729 Braga Travessa 74314 Barros Avenida Lote 48
pt_PT Renato Camp 974 Madalena Course 3 Apt. 817
ro Elton Intrarea, Bloc 79 Aimee Intrarea, Bloc 81, Ap. 695
ru Bridget проспект, 000 Garret улица, 622 кв. 979
sk Bernhard Haven 4 Hallie Orchard 8 Suite 713
sv Klara gatan 3 Karl vägen 4 Lgh. 617
tr Okumuş Summit 53b Orbay Crossroad 23a Apt. 764
uk Johnson майдан, 3 Earline майдан, 53 кв. 791
ur 7901 نیازی کالونی 783 نیازی آباد گلی 844
vi 0023 Đào Loaf 01215 Quang Triệu Harbor Apt. 530
zh_CN 龚 街54号 赖 桥37号 Apt. 372
zh_TW 昊強 西路15號 子涵 東路6325號 Apt. 443
zu_ZA 73476 Bayeni Union 601 Mbende Underpass Suite 035

@pkuczynski
Copy link
Member

Here are some examples for the generated addresses

Polish one (pl) is not Polish at all regarding both format and language. How can I improve that?

@ST-DDT
Copy link
Member Author

ST-DDT commented Apr 4, 2022

Here are some examples for the generated addresses

Polish one (pl) is not Polish at all regarding both format and language. How can I improve that?

I could change/fix the format here, but it might be best if you create a separate PR for that (format/street address, street name, building number and secondary address)

@ST-DDT
Copy link
Member Author

ST-DDT commented Apr 5, 2022

Like this?

@ST-DDT ST-DDT requested review from clarkerican and pkuczynski April 5, 2022 17:26
@ST-DDT ST-DDT requested a review from a team April 5, 2022 17:26
@ST-DDT ST-DDT enabled auto-merge (squash) April 5, 2022 21:31
@ST-DDT ST-DDT merged commit b04dc91 into main Apr 5, 2022
@ST-DDT ST-DDT deleted the feature/address/street-address-from-locales branch April 5, 2022 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: feature Request for new feature p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

address.streetAddress() doesn't use locale.address.street_address template
4 participants