| 1 |
<?php
|
| 2 |
// $Id: i18ncontent.module,v 1.1.2.1 2007/02/11 15:45:22 jareyero Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Internationalization (i18n) package - translatable content type parameters
|
| 7 |
*
|
| 8 |
* This new module uses a pure forms/strings approach as opposed to the old one (v5)
|
| 9 |
* which was using some dirty db rewrite tricks.
|
| 10 |
*
|
| 11 |
* @ TODO Handle node type changed and deleted
|
| 12 |
*
|
| 13 |
* @author Jose A. Reyero, 2007
|
| 14 |
*/
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implementation of hook_help().
|
| 18 |
*/
|
| 19 |
function i18ncontent_help($path, $arg) {
|
| 20 |
switch ($path) {
|
| 21 |
case 'admin/help#i18ncontent':
|
| 22 |
$output = '<p>'.t('This module will localize all content type configuration texts.').'</p>';
|
| 23 |
$output .= '<ul>';
|
| 24 |
$output .= '<li>'.t('Content type names').'</li>';
|
| 25 |
$output .= '<li>'.t('Submission guidelines').'</li>';
|
| 26 |
$output .= '<li>'.t('Content type descriptions were previously localized so they won\'t be affected').'</li>';
|
| 27 |
$output .= '</ul>';
|
| 28 |
return $output;
|
| 29 |
}
|
| 30 |
if ($arg[0] == 'node' && $arg[1] == 'add' && $arg[2]) {
|
| 31 |
$type = str_replace('-', '_', $arg[2]);
|
| 32 |
if ($help = ts("nodetype:$type:help")) {
|
| 33 |
return '<p>'. filter_xss_admin($help) .'</p>';
|
| 34 |
}
|
| 35 |
}
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Implementation of hook_locale().
|
| 40 |
*/
|
| 41 |
function i18ncontent_locale($op = 'groups') {
|
| 42 |
switch ($op) {
|
| 43 |
case 'groups':
|
| 44 |
return array('nodetype' => t('Content type'));
|
| 45 |
}
|
| 46 |
}
|
| 47 |
|
| 48 |
/**
|
| 49 |
* Implementation of hook_form_alter()
|
| 50 |
*/
|
| 51 |
function i18ncontent_form_alter(&$form, $form_state, $form_id) {
|
| 52 |
// Translate field names for title and body for the node edit form
|
| 53 |
if (isset($form['#id']) && $form['#id'] == 'node-form') {
|
| 54 |
$type = $form['#node']->type;
|
| 55 |
if (!empty($form['title']['#title'])) {
|
| 56 |
$form['title']['#title'] = tt("nodetype:$type:title", $form['title']['#title']);
|
| 57 |
}
|
| 58 |
if (!empty($form['body_field']['body']['#title'])) {
|
| 59 |
$form['body_field']['body']['#title'] = tt("nodetype:$type:body", $form['body_field']['body']['#title']);
|
| 60 |
}
|
| 61 |
}
|
| 62 |
// Handle submissions for node_type_forms
|
| 63 |
if ($form_id == 'node_type_form') {
|
| 64 |
$type = $form['#node_type']->type;
|
| 65 |
// We are using default language for this
|
| 66 |
$language = language_default('language');
|
| 67 |
// If we are creating a new one, just add the submission hook
|
| 68 |
if ($type) {
|
| 69 |
//$form['description']['#default_value'] = ts("nodetype:$type:description");
|
| 70 |
$form['submission']['help']['#default_value'] = ts("nodetype:$type:help", $form['submission']['help']['#default_value'], $language);
|
| 71 |
}
|
| 72 |
$form['#submit'] = array_merge(array('i18ncontent_form_submit'), $form['#submit']);
|
| 73 |
}
|
| 74 |
}
|
| 75 |
|
| 76 |
/**
|
| 77 |
* Handle content type form submissions
|
| 78 |
*/
|
| 79 |
function i18ncontent_form_submit($form, &$form_state) {
|
| 80 |
$language = language_default('language');
|
| 81 |
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
|
| 82 |
$type = trim($form_state['values']['type']);
|
| 83 |
$old_type = isset($form_state['values']['old_type']) ? $form_state['values']['old_type'] : $type->type;
|
| 84 |
if ($op == t('Reset to defaults')) {
|
| 85 |
// Do anything?;
|
| 86 |
}
|
| 87 |
elseif ($op == t('Delete content type')) {
|
| 88 |
// Delete strings
|
| 89 |
tt("nodetype:$type:name", NULL, NULL, TRUE);
|
| 90 |
tt("nodetype:$type:help", NULL, NULL, TRUE);
|
| 91 |
} else {
|
| 92 |
// Update sources if changed type id
|
| 93 |
if ($old_type && $old_type != $type) {
|
| 94 |
i18nstrings_update_context("nodetype:$old_type:*", "nodetype:$type:*");
|
| 95 |
}
|
| 96 |
tt("nodetype:$type:name", $form_state['values']['name'], $language, TRUE);
|
| 97 |
ts("nodetype:$type:help", $form_state['values']['help'], $language, TRUE);
|
| 98 |
// We remove help text so it's not produced later by node module
|
| 99 |
$form_state['values']['help'] = '';
|
| 100 |
}
|
| 101 |
}
|
| 102 |
|
| 103 |
/**
|
| 104 |
* Implementation of hook_menu_alter().
|
| 105 |
*
|
| 106 |
* Take over the node add pages
|
| 107 |
*/
|
| 108 |
function i18ncontent_menu_alter(&$menu) {
|
| 109 |
foreach ($menu as $path => $item) {
|
| 110 |
if (!empty($item['page callback']) && $item['page callback'] == 'node_add') {
|
| 111 |
$arg = arg(NULL, $path);
|
| 112 |
$menu[$path]['title callback'] = 'i18nstrings_title_callback';
|
| 113 |
$menu[$path]['title arguments'] = array('nodetype:'.$arg[2].':name', $item['title']);
|
| 114 |
}
|
| 115 |
}
|
| 116 |
}
|
| 117 |
|
| 118 |
|
| 119 |
/**
|
| 120 |
* Replacement for node_add_page
|
| 121 |
*/
|
| 122 |
function i18ncontent_node_add_page() {
|
| 123 |
$item = menu_get_item();
|
| 124 |
$content = system_admin_menu_block($item);
|
| 125 |
//dsm($content);
|
| 126 |
return theme('node_add_list', $content);
|
| 127 |
}
|
| 128 |
|