Hi,
I have nodes with location info through feedapi feeds which only hold countrynames, not isocodes.
This seems problematic within location module. Everything seems to be depending on Country ISO codes.

- How can I get from a countryname to the specific ISO-code? Is there a function within location?
For example I have the countryname; holland, or nederland and needs to get the ISO code of the netherlands with it, which is nl
- If I then have the country ISO code, how can I then translate the english countryname with this to dutch?
With ISO-code NL, location shows "The Netherlands", but I would like to show "Nederland".

Thanks for your reply!
Greetings,
Martijn

Comments

yesct’s picture

hanno’s picture

Can the module Country codes API (http://drupal.org/project/countries_api) help you with this?
There is a patch for this module for a Dutch translation of the country names: http://drupal.org/node/382828

summit’s picture

Hi,

How to get from countryname to countrycode? This part of the puzzle is still for me not to crasp..
Filed a issues on country api also: http://drupal.org/node/487296
greetings,
Martijn

summit’s picture

On http://drupal.org/node/487296 , Tom Kirkpatrick explained beneath code to get from countryname to iso2 code

<?php
$iso2 = db_result(db_query("select iso2 from {countries_api_countries} where name = '%s'", $countryname));
?>

Still the problem of having different country-names in my feeds. For instance:
a feed which shows in the country-field: "United states of America"
another feed shows in the country-field: "United states"
another feed shows in the country-field: "America"
They all mean the same.

How can I automated still get to the right iso countrycode. Pseudocode:
First get from the different country-fields to the right $countryname. Then use above code to get to the right $iso2.

How to get this working please?

Thanks a lot in advance! greetings, Martijn

summit’s picture

Will something like this work?

<?php 
 $united_states_possibilities= array(" usa", "united states of america", "america");
 $correct_united_states= str_replace($united_states_possibilities, "United States", $countryname);
 $iso2 = db_result(db_query("select iso2 from {countries_api_countries} where name = '%s'", $countryname));
?>

For translation to dutch I can use http://drupal.org/project/countries_api

Please advice whole structure to first get from possibiliteis to right country id.
Thanks in advance greetings, Martijn

mrfelton’s picture

bear in mind that the 'name' column stores the official country names (in upper case).. The 'printable_name' column stores them in a printable format. So, you should probably run strtolower($countryname) when you perform your match.

rooby’s picture

Status: Active » Fixed

There is a function the the location module uses for its country list location_get_iso3166_list() in location.inc.

Calling location_get_iso3166_list() or location_get_iso3166_list(FALSE) will give you lower case country codes and calling location_get_iso3166_list(TRUE) will give you upper case country codes.

It returns an array of country_code => country_name pairs so you could use something like this to get the code for a country name:

<?php
  $your_country_name = 'whatever';
  $countries = location_get_iso3166_list();
  $countries = array_flip($countries);
  $your_country_code = $countries[$your_country_name];
?>

or

<?php
  $your_country_name = 'whatever';
  $countries = location_get_iso3166_list();
  $your_country_code = array_search($your_country_name, $countries);
?>

In regards to translations, all the countries in the country list are run through the t() function so if there is a dutch translation for the location module you should just be able to use that.
Otherwise you can just use drupals translation functionality to translate it manually.

Status: Fixed » Closed (fixed)
Issue tags: -location translation, -location ISO codes

Automatically closed -- issue fixed for 2 weeks with no activity.