Skip Menu |

This queue is for tickets about the Locale-Codes CPAN distribution.

Report information
The Basics
Id: 92680
Status: resolved
Priority: 0/
Queue: Locale-Codes

People
Owner: Nobody in particular
Requestors: cpan [...] iijo.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.29
Fixed in: (no value)



Subject: rename_country() is broken for country aliases with Locale::Codes v3.29
The following code describes the problem: use Locale::Country; Locale::Country::rename_country('us' => 'the United States'); code2country('us'); # returns 'United States' instead of 'the United States' This used to work in v3.27. Also note that this works correctly: use Locale::Country; Locale::Country::rename_country('us' => 'boop'); code2country('us'); # returns 'boop'
In version 3.29, I rewrote some of my data gathering scripts in an effort to avoid data omissions. Unfortunately, I got an index wrong for aliases which broke the rename_* functions. As far as I can tell, it has no other impact, and these functions are used extremely infrequently, so I don't believe that it merits an early general release, so at this point, I plan to release this with 3.30 scheduled for Mar 1. However, if you need it sooner than that, you can download an interim version from: http://sullybeck.com/Locale-Codes-3.30.tar.gz
Thanks! Your fix works nicely. I have a small nitpick with your new version (3.30) though. It seems to capitalize the first letter of a country's name when I use add_country_alias() or rename_country(). For example when I want to rename a country to 'the United States'. The 'the' gets capitalized but I would prefer if it did not.
Correction: the capitalization thing is only relevant for rename_country() not add_country_alias(). The capitalization does not seems to happen consistently though. It seems to depend on the country name. Here is a test case demonstrating the problem and the inconsistency: use Locale::Country; # returns 'Russian Federation' code2country('ru'); # returns 'The Russian Federation' Locale::Country::rename_country('ru' => 'the Russian Federation'); code2country('ru'); # returns 'Virgin Islands (U.S.)' code2country('vi'); # returns 'the US Virgin Islands' Locale::Country::rename_country('vi' => 'the US Virgin Islands'); code2country('vi');
Here is another more serious issue: use Locale::Country; code2country('kp'); # returns 'Korea, The Democratic People\'s Republic of' Locale::Country::rename_country('kp' => "the Republic of Korea"); # dies with this error: # 'rename_country(): rename to an existing country not allowed'
With respect to the capitalization comment: I see what is going on. Believe it or not, Locale::Codes is not capitalizing your change... but it IS treating aliases as case insensitive. When you rename the country to 'the Russian Federation', it checks to see if there is an alias by that name (and aliases are stored in a case insensitive hash... i.e. all lowercase), and 'The Russian Federation' is already listed as an alias, so Locale::Codes is just assuming that you want to use that alias. If you rename it to 'a Russian Federation' (which does not already exist), then the return value is capitalized as passed in. I understand that this is a nuisance, and I could fix it by making the alias hash case sensitive. It's a bit of work... but not undoable by any means. I want to consider it for a while, so I'll add it to my TODO list, and look at it as a possible change for the next release. With respect to the 'more serious issue'... I'm afraid you're trying to do something bad here. There are two countries named 'The Republic of Korea' and 'The Democratic People's Republic of Korea' and you're trying to rename one to be the other. Locale::Codes gives a fatal error. I maybe could make the error non-fatal, but I certainly won't add support for the rename to occur. Hope that clarifies things.
Yes it does, thanks! My code now works great with v3.30. I added some tests to my code base for that highly embarrassing Korea gaffe. I am just awaiting the CPAN release now. :) No hurry though.