Skip to content

fix(geo): resolve countries by their catalog name - #121

Open
AnasIsmai1 wants to merge 1 commit into
Younesfdj:masterfrom
AnasIsmai1:fix/geo-iso-country-names
Open

fix(geo): resolve countries by their catalog name#121
AnasIsmai1 wants to merge 1 commit into
Younesfdj:masterfrom
AnasIsmai1:fix/geo-iso-country-names

Conversation

@AnasIsmai1

Copy link
Copy Markdown

The bug

countryFromLocation matches a profile's location against a hand-written map in lib/geo.ts — about 95 country codes. We ship flags for 253. So a profile whose location simply named its country flew no flag at all:

"Dakar, Senegal"                     -> null
"Amman, Jordan"                      -> null
"Sarajevo, Bosnia and Herzegovina"   -> null
"Tashkent, Uzbekistan"               -> null
"Abidjan, Côte d'Ivoire"             -> null

public/badges/flags/sn.png, jo.png, ba.png, uz.png and ci.png were all sitting right there. 10 of the 48 teams at WC26 were unreachable this way: Senegal, Jordan, Uzbekistan, Cape Verde, DR Congo, Côte d'Ivoire, Curaçao, Haiti, Panama, Bosnia and Herzegovina.

The root cause isn't any one missing country — it's that the name list is maintained by hand while lib/countries.ts is auto-generated from the flag assets and already pairs every shipped flag with its English name. Adding countries one at a time just refills the same gap later.

The fix

Fall back to COUNTRIES when the curated map doesn't answer. The catalog becomes the source, so a new flag asset is reachable the moment gen-countries.mjs runs.

Three constraints kept it from becoming a looser matcher:

  • Exact-segment lookups only. Catalog names are deliberately kept out of MULTIWORD — substring matching across 253 names would read "Indiana" as India, "Nigeria" as Niger and "Romania" as Oman.
  • Second pass, after the curated sources. The alias map, US states and cities are higher-confidence and still win, so "Chad, Nebraska" is still the US state and "Manchester, UK" is still England.
  • Official long names resolve by head only when unambiguous. "Tanzania, United Republic of" indexes tanzania, but "Congo" stays the Republic (it's that country's whole name) and "Virgin Islands" stays unresolved rather than guessing between the British and US ones — no flag still beats the wrong flag.

DR Congo gets the aliases people actually type (DR Congo, Democratic Republic of the Congo, DRC), since the head rule refuses it on purpose.

One more detail: the location cleaner is now a shared fold() applied to both sides. "Côte d'Ivoire" only matches because the catalog name loses its apostrophe to the same regex the location does.

Result

Countries resolvable by their own name:

before after
lib/countries entries that resolve 96 / 253 249 / 253

The four that remain are the ambiguous comma'd ISO long forms described above (Congo, the Democratic Republic of the, Korea, Democratic People's Republic of, and both Virgin Islands) — left unresolved by design, with DR Congo reachable via its aliases.

Tests

5 new blocks in tests/geo.test.ts covering the newly-resolving WC26 teams, the accent/apostrophe fold, the head-only-when-unambiguous rule, the curated sources still winning, and the substring cases that must not match.

npm test        304 passed (23 files)   # was 299
npm run lint    0 errors                # 14 pre-existing warnings, unchanged
npm run build   compiled successfully

Note on #113

That PR is still needed and doesn't conflict in substance: we ship no il.png, so Israel can't come from the catalog until the asset lands. Once it does, this change resolves it with no further edit to lib/geo.ts.

🤖 Generated with Claude Code

countryFromLocation matched country names against a hand-written map of
~95 codes, while we ship flags for 253. A profile whose location simply
named its country flew no flag at all: "Dakar, Senegal", "Amman,
Jordan", "Sarajevo, Bosnia and Herzegovina" all resolved to null — 10 of
the 48 teams at WC26 among them.

Fall back to lib/countries, which already pairs every shipped flag with
its English name, so the catalog is the source instead of a list that
has to be extended by hand each time someone files a missing country.

Exact-segment lookups only, as a second pass after the curated sources:
- Substring matching across 253 names would read "Indiana" as India,
  "Nigeria" as Niger and "Romania" as Oman, so catalog names stay out of
  MULTIWORD.
- The curated map, US states and cities still win, so "Chad, Nebraska"
  is still the US state and "Manchester, UK" is still England.
- An official long name's head ("Tanzania, United Republic of") is
  indexed only when exactly one country claims it, leaving "Congo" on
  the Republic and "Virgin Islands" unresolved rather than guessed.

DR Congo gets the aliases people actually type, since the head rule
deliberately refuses it.

Country names resolvable by their own name: 96/253 -> 249/253. The four
that remain are the ambiguous comma'd long forms above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant