FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* The administration interface.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Header of the translation table.
|
||||
*
|
||||
* @param $languages
|
||||
* languages to translate to
|
||||
*
|
||||
* @return
|
||||
* header row for theme_table
|
||||
*/
|
||||
function _translation_table_get_header($languages) {
|
||||
// FIXME: this sortable header won't work, why?
|
||||
// $header = array(array('data' => t('Original'), 'sort' => 'asc', 'field' => 'source'));
|
||||
$header = array(array('data' => t('Original')));
|
||||
|
||||
foreach ($languages as $lang_code => $lang_name) {
|
||||
$header[] = array('data' => $lang_name);
|
||||
}
|
||||
|
||||
$header[] = array('data' => t('Operations'), 'colspan' => 3);
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* One row of the translation table.
|
||||
*
|
||||
* @param $source
|
||||
* source string record
|
||||
* @param $languages
|
||||
* languages to translate to
|
||||
* @return
|
||||
* table row for theme_table
|
||||
*/
|
||||
function _translation_table_row($source, $languages) {
|
||||
$form['source'] = array(
|
||||
'#markup' => check_plain($source->source),
|
||||
);
|
||||
$form['location'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => check_plain($source->location),
|
||||
);
|
||||
|
||||
foreach ($languages as $lang_code => $lang_name) {
|
||||
$translation = db_query("SELECT lt.translation FROM {locales_target} lt WHERE lt.lid = :lid AND lt.language = :lang", array('lid' => $source->lid, 'lang' => $lang_code))->fetchField();
|
||||
$form[$lang_code] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $translation,
|
||||
'#size' => 35,
|
||||
'#maxlength' => NULL,
|
||||
);
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for the translation table.
|
||||
*/
|
||||
function translation_table_submit_translations($form, &$form_state) {
|
||||
switch ($form_state['clicked_button']['#id']) {
|
||||
case 'edit-submit':
|
||||
$language_list = locale_language_list('language', TRUE);
|
||||
foreach ($form_state['values']['strings'] as $lid => $values) {
|
||||
foreach ($values as $lang_code => $translation) {
|
||||
if (in_array($lang_code, $language_list)) {
|
||||
_translation_table_update_translation($lid, $lang_code, $translation);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Redirect to current page.
|
||||
$query = isset($_GET['page']) ? array('page' => $_GET['page']) : array();
|
||||
$form_state['redirect'] = array($_GET['q'], $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update, create or delete translation as needed.
|
||||
*/
|
||||
function _translation_table_update_translation($lid, $lang_code, $translation) {
|
||||
if ($translation == '') {
|
||||
db_query("DELETE FROM {locales_target} WHERE lid = :lid AND language = :lang", array('lid' => $lid, 'lang' => $lang_code));
|
||||
return;
|
||||
}
|
||||
db_merge("locales_target")
|
||||
->key(array('language' => $lang_code, 'lid' => $lid, 'plural' => 0))
|
||||
->fields(array('translation' => $translation))
|
||||
->execute();
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* The functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Theme function for the translation table.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_translation_table($variables) {
|
||||
$form = $variables['form'];
|
||||
$rows = array();
|
||||
$header = $form['header']['#value'];
|
||||
$languages = $form['languages']['#value'];
|
||||
|
||||
foreach (element_children($form['strings']) as $key) {
|
||||
// Build the table row.
|
||||
$row = array();
|
||||
$row['data'][] = array('data' => drupal_render($form['strings'][$key]['source']), 'class' => 'translation-source');
|
||||
|
||||
foreach ($languages as $lang_code => $lang_name) {
|
||||
$row['data'][] = array('data' => drupal_render($form['strings'][$key][$lang_code]), 'class' => 'translation-'. $lang_code);
|
||||
};
|
||||
$location = explode(':', $form['strings'][$key]['location']['#value']);
|
||||
if (count($location) == 4) {
|
||||
switch ($location[1]) {
|
||||
case 'term':
|
||||
$row['data'][] = l(t('Edit source'), 'admin/content/taxonomy/edit/term/'. $location[1], array('attributes' => array('title' => t('Edit term (@property)', array('@property' => t($location[2]))))));
|
||||
break;
|
||||
|
||||
case 'vocabulary':
|
||||
$row['data'][] = l(t('Edit source'), 'admin/content/taxonomy/edit/vocabulary/'. $location[1], array('attributes' => array('title' => t('Edit vocabulary (@property)', array('@property' => t($location[2]))))));
|
||||
break;
|
||||
|
||||
case 'item':
|
||||
$row['data'][] = l(t('Edit source'), 'admin/build/menu/item/'. $location[1] .'/edit', array('attributes' => array('title' => t('Edit menu item (@property)', array('@property' => t($location[2]))))));
|
||||
break;
|
||||
|
||||
case 'type':
|
||||
$node_types = node_type_get_names();
|
||||
$node_type = isset($node_types[$location[1]]) ? $node_types[$location[1]] : $location[1];
|
||||
$row['data'][] = l(t('Edit source'), 'admin/content/node-type/'. $location[1], array('attributes' => array('title' => t('Edit @node_type (@property)', array('@node_type' => $node_type, '@property' => t($location[2]))))));
|
||||
break;
|
||||
|
||||
default:
|
||||
$row['data'][] = '';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$row['data'][] = '';
|
||||
}
|
||||
$row['data'][] = l(t('Translate'), 'admin/config/regional/translate/edit/'. $key);
|
||||
$row['data'][] = l(t('Delete string'), 'admin/config/regional/translate/delete/'. $key);
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
$output = theme('table', array(
|
||||
'header' => $header,
|
||||
'rows' => $rows,
|
||||
'attributes' => array('id' => 'translation-table')
|
||||
));
|
||||
|
||||
if ($form['pager']['#markup']) {
|
||||
$output .= drupal_render($form['pager']);
|
||||
}
|
||||
$output .= drupal_render_children($form);
|
||||
|
||||
drupal_add_css(drupal_get_path('module', 'translation_table') .'/css/translation-table-admin.css');
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme function for the basic filter form.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_translation_table_filter($variables) {
|
||||
$form = $variables['form'];
|
||||
$output = '<div id="translation-table-filter">';
|
||||
foreach (element_children($form) as $key) {
|
||||
$attributes = drupal_attributes(array(
|
||||
'id' => 'translation-table-'. str_replace('_', '-', $key) .'-filter',
|
||||
'class' => 'translation-table-filter',
|
||||
));
|
||||
$output .= "<div $attributes>";
|
||||
$output .= drupal_render($form[$key]);
|
||||
$output .= '</div>';
|
||||
}
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
Reference in New Issue
Block a user