You are here

function countries_t in Countries 8

Same name and namespace in other branches
  1. 7.2 countries.module \countries_t()

Wrapper function to hook into the countries_i18n module.

1 call to countries_t()
country_property in ./countries.module
Helper function to help standardise the display of the core properties.
1 string reference to 'countries_t'
countries_clear_caches in ./countries.module
Helper function to clear various caches.

File

./countries.module, line 122
Defines the field and entity information for countries.

Code

function countries_t($country, $property = 'name', $langcode = NULL) {

  // If not specified, we use the global interface language, $language, rather
  // than the global content language, $language_content.
  global $language;

  // @todo investigate if we can get LANGUAGE_NONE here.
  if (empty($langcode) || $langcode == LANGUAGE_NONE) {
    $langcode = $language->language;
  }
  static $i18n = NULL;
  if (!isset($i18n)) {
    $i18n = module_exists('countries_i18n');
  }
  switch ($property) {
    case 'name':
    case 'official_name':
      $value = (string) $country->{$property};

      // Only translate as required.
      if ($i18n && $country->language != $langcode) {
        $translations =& drupal_static(__FUNCTION__, array());
        $key = $country->iso2 . ':' . $langcode . ':' . $property;
        if (!isset($translations[$key])) {
          $translations[$key] = countries_i18n_translate($country->iso2, $property, $value, $langcode, 'country');
        }
        return $translations[$key];
      }
      return $value;
    default:
      return isset($country->{$property}) ? $country->{$property} : '';
  }
}