I'm using $location['country'] to output the country right now, but that only outputs the 2 letter abbreviation for the country. Does anyone know how I can output the full country name? Like 'United States' instead of 'us'.

Thanks.

Comments

geodaniel’s picture

Assigned: Unassigned » geodaniel
Status: Active » Fixed

To get the full country name of the US, for example, you could use:

  $country_names = location_get_iso3166_list();
  print $country_names['us'];
Anonymous’s picture

Status: Fixed » Closed (fixed)
sodani’s picture

Status: Closed (fixed) » Active

so can you tell me how this should be coded if I want to use the variable, $location['country'] instead of 'us' ? That code works specifically if I want to output 'United States' but not for outputting a variable. Apologies for the noobie php question.

geodaniel’s picture

I'm not sure which bit of code you're trying to change? Where is the display of 'us' that you want to change to the country name?

sodani’s picture

you had pasted the following code:

<?php
  $country_names = location_get_iso3166_list();
  print $country_names['us'];
?>

which outputs 'United States'. I'd like the code to output the full name of whatever country is attached to that node. I assume that $country_names['us'] just needs to be changed so that the thing inside the brackets is a variable.

Also, do you happen to know how to manually output the entire location? I'm noticing that if I use contemplates, location doesn't get outputted unless you somehow tell it to.

bassio’s picture

Status: Active » Closed (fixed)

administer -> site configuration -> location settings -> display by default

bsuttis’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Status: Closed (fixed) » Active

I'm not finding the 'display by default' option at /admin/settings/location, was this feature removed? I'm using the latest dev of Location

bdragon’s picture

Status: Active » Fixed

In 3.x, $country_name is available.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

Chad_Dupuis’s picture

You can get the current country name from the url arguments. So assuming you have something like: http://yourhost.com/directory/us/CA/ you can use something like the following:
Where arg(0) would be "directory", arg(1) "us", and arg(2) "CA", etc.

  $country_names = location_get_iso3166_list();
  $currentcountry = arg(1);
  print $country_names[$currentcountry];
summit’s picture

On #8 (http://drupal.org/comment/reply/87296/1113108#comment-1052114) $country_name is added in 3.dev. Does this mean that this code works:

  $country_names = location_get_iso3166_list();
  print $country_names[$country_name];

Thanks a lot in advance for your reply!

greetings,
Martijn