phone icon indicating copy to clipboard operation
phone copied to clipboard

Missing and/or incorrect country codes

Open elskwid opened this issue 14 years ago • 8 comments

It seems the data extraction from http://commondatahub.com/live/geography/country/country_dialing_codes may have had a couple of issues.

There are multiple instances of countries sharing a country code. US & Canada are a good example. Today I was looking for Australia in phone_countries.yml and found

"61": 
  :country_code: "61"
  :national_dialing_prefix: "0"
  :char_2_code: "0"
  :char_3_code: CC
  :name: Cocos (Keeling) Islands
  :international_dialing_prefix: "11"

Turns out Cocos is a territory of Australia (Thanks Wikipedia!).

I also see that Norway is not in the file, but Svalbard is. My guess is that the data extraction just overwrote previous country code entries as it progressed. Which means we got luck with the US and Italy as Italy and the Holy See share a code.

Sorting the commondatahub table on dialing country code shows some others.

My first instinct is to just change the offending entires in phone_countries.yml to the more commonly recognized countries. However, this doesn't make much sense if the countries file is going to be automatically regenerated in the future.

elskwid avatar Jul 30 '10 20:07 elskwid

I agree that something needs to be done about this. I'd be willing to re-extract the data from the above url, but it seems the issue lies in the YAML "key" being the same as the :country_code. I would content that the key simply needs to be a unique (incrementing?) value, thereby allowing multiple countries to share a country_code.

sterrym avatar Aug 06 '10 18:08 sterrym

@sterrym: the trouble with sharing a country_code is that the parsing is keyed off the country_code - so how would the library decide what parsing rules to use?

The point seems to be that in some cases the dialing rules span "country" boundaries. My example about Australia vs Cocos Islands means that you dial the Cocos just like you would Australia and use the "area code" for the Cocos - it's a subset of the Australian phone system.

elskwid avatar Aug 06 '10 22:08 elskwid

@eskwid I'm not saying that there shouldn't be a country_code. I would argue that the country_code doesn't also have to be the key for the yml-created hash. The commondatahub link you provided above lists 24 countries that all share the "1" country_code. with that number of countries getting clobbered, I would contend that it's worth finding a different way.

The only method I can see that uses this as a key is this in phone_country.rb:

def self.find_by_country_code(code)
  @@all[code]    
end

In my use case, I am developing for a Canadian client with customers all over the world. It's not really an option for them to only have the United States listed for the "1" code.

So I suppose the question is, do all the countries that share the "1" country_code also have the same formatting/parsing rules? If not, then we can still limp by with this. If so, then it gets harder.

sterrym avatar Aug 09 '10 13:08 sterrym

All countries using the "1" country code use the same formatting rules.

Once issue 29 has been addressed, I'll fix up some of the other problems after re-base of repo.

g1smd avatar Aug 25 '12 06:08 g1smd

All countries using the "1" country code use the same formatting rules.

Once issue 29 has been addressed, I'll fix up some of the other problems after re-base of repo; though I hate having to wait two weeks already to do this.

g1smd avatar Sep 11 '12 00:09 g1smd

Looks like hell will freeze over before I get an answer. Issue 29 still awaits review.

g1smd avatar Nov 12 '12 23:11 g1smd

Hey guys, been a long time! I'm going to making a pass through issues soon. See #41.

elskwid avatar May 09 '13 18:05 elskwid

I have user-originated phone numbers with a mix of "phone / tel / ..." in front or at the end of my strings, and I need to support Norway (curently clobbered as described above). Is it only the data import feature and elf.find_by_country_code(code) that is affected? Sounds easy to fix. Patches welcome?

sesam avatar Jan 19 '15 12:01 sesam