View source
<?php
function translation_overview_help($path, $arg) {
switch ($path) {
case 'admin/content/translation_overview':
$args = array();
$statuses = array(
'original',
'current',
'outofdate',
'missing',
);
foreach ($statuses as $status) {
$args['!' . $status] = theme('translation_overview_status_img', $status, $status);
}
return '<p>' . t('The table uses the following symbols to indicate the translation status: !original Original language, !current Current translation, !outofdate Out-of-date translation, !missing Untranslated.', $args) . '</p>';
}
}
function translation_overview_menu() {
$items = array();
$items['admin/content/translation_overview'] = array(
'title' => 'Translation overview',
'type' => MENU_NORMAL_ITEM,
'description' => "View the translation status of the site's content.",
'page callback' => 'translation_overview_overview_page',
'file' => 'translation_overview.pages.inc',
'access arguments' => array(
'translate content',
),
);
$items['admin/content/translation_overview/all'] = array(
'title' => 'All',
'description' => 'All translations',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -20,
'access arguments' => array(
'translate content',
),
);
foreach (language_list() as $key => $language) {
if ($language->enabled) {
$items['admin/content/translation_overview/' . $language->language] = array(
'title' => $language->language,
'description' => $language->name,
'type' => MENU_LOCAL_TASK,
'page callback' => 'translation_overview_language_page',
'page arguments' => array(
$language->language,
),
'file' => 'translation_overview.pages.inc',
'access arguments' => array(
'translate content',
),
);
}
}
return $items;
}
function translation_overview_theme() {
return array(
'translation_overview_translation_link' => array(
'arguments' => array(
'status' => NULL,
'path' => '',
'options' => array(),
'show_long' => FALSE,
),
),
'translation_overview_status_img' => array(
'arguments' => array(
'status' => NULL,
'alt_text' => '',
),
),
);
}
function translation_overview_node_types() {
$types = array();
foreach (node_get_types('names') as $type => $name) {
if (translation_supported_type($type)) {
$types[$type] = $name;
}
}
return $types;
}
function translation_overview_translation_link($node, $translation_nid, $language, $show_long = FALSE) {
$path = 'node/' . $node->nid;
$options = array();
if ($language == $node->language) {
return theme('translation_overview_translation_link', 'original', $path, $options, $show_long);
}
if (!empty($translation_nid)) {
$tnode = node_load($translation_nid);
if ($tnode->nid) {
if (node_access('update', $tnode)) {
$path = "node/{$tnode->nid}/edit";
$options['query'] = array(
'destination' => $_GET['q'],
);
}
else {
$path = 'node/' . $tnode->nid;
}
if ($tnode->translate == 0) {
return theme('translation_overview_translation_link', 'current', $path, $options, $show_long);
}
return theme('translation_overview_translation_link', 'outofdate', $path, $options, $show_long);
}
}
$path = '';
if (node_access('create', $node)) {
$path = 'node/add/' . str_replace('_', '-', $node->type);
$options['query'] = array(
'destination' => $_GET['q'],
'translation' => $node->nid,
'language' => $language,
);
}
return theme('translation_overview_translation_link', 'missing', $path, $options, $show_long);
}
function theme_translation_overview_status_img($status, $alt_text) {
$img_path = drupal_get_path('module', 'translation_overview') . "/status_{$status}.png";
return theme('image', $img_path, $alt_text);
}
function theme_translation_overview_translation_link($status, $path, $options = array(), $show_long = FALSE) {
switch ($status) {
case 'original':
$long = t('Original');
$options['attributes'] = array(
'title' => t('View original'),
);
break;
case 'current':
$long = t('Complete');
if (preg_match('/node\\/\\d*\\/edit/', $path)) {
$options['attributes'] = array(
'title' => t('Translation is up-to-date, edit it'),
);
}
else {
$options['attributes'] = array(
'title' => t('Translation is up-to-date, view it'),
);
}
break;
case 'outofdate':
$long = t('Out-of-date');
if (preg_match('/node\\/\\d*\\/edit/', $path)) {
$options['attributes'] = array(
'title' => t('Translation is out-of-date, edit it'),
);
}
else {
$options['attributes'] = array(
'title' => t('Translation is out-of-date, view it'),
);
}
break;
case 'missing':
$long = t('Untranslated');
$options['attributes'] = array(
'title' => t('Translation does not exist, create it'),
);
break;
}
$text = theme('translation_overview_status_img', $status, $long) . ($show_long ? ' ' . $long : '');
$options['html'] = TRUE;
if ($path) {
return l($text, $path, $options);
}
return $text;
}