6 * Internationalization (i18n) package - translatable content type parameters
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.
11 * @ TODO Handle node type changed and deleted
13 * @author Jose A. Reyero, 2007
17 * Implementation of hook_help().
19 function i18ncontent_help($path, $arg) {
21 case
'admin/help#i18ncontent':
22 $output = '<p>'.
t('This module will localize all content type configuration texts.').
'</p>';
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>';
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>';
39 * Implementation of hook_locale().
41 function i18ncontent_locale($op = 'groups') {
44 return array('nodetype' => t('Content type'));
49 * Implementation of hook_form_alter()
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']);
58 if (!empty($form['body_field']['body']['#title'])) {
59 $form['body_field']['body']['#title'] = tt("nodetype:$type:body", $form['body_field']['body']['#title']);
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
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);
72 $form['#submit'] = array_merge(array('i18ncontent_form_submit'), $form['#submit']);
77 * Handle content type form submissions
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')) {
87 elseif ($op == t('Delete content type')) {
89 tt("nodetype:$type:name", NULL
, NULL
, TRUE
);
90 tt("nodetype:$type:help", NULL
, NULL
, TRUE
);
92 // Update sources if changed type id
93 if ($old_type && $old_type != $type) {
94 i18nstrings_update_context("nodetype:$old_type:*", "nodetype:$type:*");
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'] = '';
104 * Implementation of hook_menu_alter().
106 * Take over the node add pages
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']);
120 * Replacement for node_add_page
122 function i18ncontent_node_add_page() {
123 $item = menu_get_item();
124 $content = system_admin_menu_block($item);
126 return theme('node_add_list', $content);