You are here

path_metatags_i18n.module in Path metatags 7

Internationalization (i18n) integration.

File

path_metatags_i18n/path_metatags_i18n.module
View source
<?php

/**
 * @file
 * Internationalization (i18n) integration.
 */

/**
 * Implements hook_i18n_string_info().
 */
function path_metatags_i18n_i18n_string_info() {
  $groups['path_metatags'] = array(
    'title' => t('Path metatags'),
    'description' => t('Translatable path metatags values.'),
    'format' => FALSE,
    'list' => FALSE,
  );
  return $groups;
}

/**
 * Implements hook_i18n_object_info().
 */
function path_metatags_i18n_i18n_object_info() {

  // Generic object properties, title, etc.
  $info['path_metatags'] = array(
    'title' => t('Path metatags'),
    // Field to be used as key to index different path metatags.
    'key' => 'machine_name',
    'class' => 'i18n_path_metatags_object',
    'load callback' => 'path_metatags_load_by_name',
    // Mapping object fields and menu place holders.
    'placeholders' => array(
      '%path_metatags_ui_cache' => 'machine_name',
    ),
    // Path for automatically generated translation tabs. Note placeholders above are used here.
    'edit path' => 'admin/structure/path-metatags/edit/%path_metatags_ui_cache',
    'translate tab' => 'admin/structure/path-metatags/edit/%path_metatags_ui_cache/translate',
    // Metadata for string translation.
    'string translation' => array(
      'textgroup' => 'path_metatags',
      'type' => 'path_metatags',
      'properties' => array(),
      'translate path' => 'admin/structure/path-metatags/edit/%path_metatags_ui_cache/translate/%i18n_language',
    ),
  );
  return $info;
}

/**
 * Implements hook_path_metatags_save().
 */
function path_metatags_i18n_path_metatags_save($path_metatags) {
  if ($path_metatags->translatable) {
    i18n_string_object_update('path_metatags', $path_metatags);
  }
  else {
    i18n_string_object_remove('path_metatags', $path_metatags);
  }
}

/**
 * Implements hook_path_metatags_delete().
 */
function path_metatags_i18n_path_metatags_delete($path_metatags) {
  i18n_string_object_remove('path_metatags', $path_metatags);
}

/**
 * Implements hook_path_metatags_view().
 */
function path_metatags_i18n_path_metatags_view($path_metatags, $contexts) {

  // Alter path_metatags object with translated strings.
  if ($path_metatags->translatable) {
    foreach ($path_metatags->metatags_values as $key => $value) {
      $path_metatags->metatags_values[$key] = i18n_string(array(
        'path_metatags',
        'path_metatags',
        $path_metatags->machine_name,
        $key,
      ), $value);
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function path_metatags_i18n_form_path_metatags_ui_metatags_list_alter(&$form, $form_state) {

  // Do not process form if there are no metatags.
  if (empty($form_state['storage']['objects'])) {
    return;
  }
  foreach ($form_state['storage']['objects'] as $path_metatags) {
    if ($path_metatags->translatable) {
      $form[$path_metatags->machine_name]['actions']['#links'][] = array(
        'title' => t('Translate'),
        'href' => 'admin/structure/path-metatags/edit/' . $path_metatags->machine_name . '/translate',
      );
    }
  }
}