fix(geo): resolve countries by their catalog name - #121
Open
AnasIsmai1 wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
countryFromLocationmatches a profile's location against a hand-written map inlib/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:public/badges/flags/sn.png,jo.png,ba.png,uz.pngandci.pngwere 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.tsis 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
COUNTRIESwhen the curated map doesn't answer. The catalog becomes the source, so a new flag asset is reachable the momentgen-countries.mjsruns.Three constraints kept it from becoming a looser matcher:
MULTIWORD— substring matching across 253 names would read"Indiana"as India,"Nigeria"as Niger and"Romania"as Oman."Chad, Nebraska"is still the US state and"Manchester, UK"is still England."Tanzania, United Republic of"indexestanzania, 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:
lib/countriesentries that resolveThe 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.tscovering 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.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 tolib/geo.ts.🤖 Generated with Claude Code