Projet

Général

Profil

Paste
Télécharger (5,49 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / i18n / i18n_forum / i18n_forum.module @ 9faa5de0

1
<?php
2

    
3
/**
4
 * @file
5
 * i18n forum module
6
 *
7
 * Internationalization (i18n) package.
8
 */
9

    
10
/**
11
 * Implements hook_help().
12
 */
13
function i18n_forum_help($path, $arg) {
14
  if ($path == 'admin/structure/forum' && ($vocabulary = i18n_forum_vocabulary())) {
15
    $base_path = 'admin/structure/taxonomy/' . $vocabulary->machine_name;
16
    return t('To translate the forum, <a href="@edit">edit and make it translatable</a>, then <a href="@translate">translate the forum</a> and <a href="@list">its containers and sub-forums</a> on the taxonomy administration page.', array(
17
      '@edit' => url($base_path . '/edit'),
18
      '@translate' => url($base_path . '/translate'),
19
      '@list' => url($base_path . '/list'))
20
    );
21
  }
22
}
23

    
24
/**
25
 * Implements hook_menu_local_tasks_alter().
26
 */
27
function i18n_forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {
28
  // Translate link to 'node/add/forum' on 'forum' sub-pages.
29
  if ($root_path == 'forum' || $root_path == 'forum/%') {
30
    $tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->tid : 0);
31
    $forum_term = forum_forum_load($tid);
32
    if ($forum_term) {
33
      // Loop through all bundles for forum taxonomy vocabulary field.
34
      $vid = variable_get('forum_nav_vocabulary', 0);
35
      if ($vid && ($vocabulary = taxonomy_vocabulary_load($vid)) && ($field = field_info_field('taxonomy_' . $vocabulary->machine_name))) {
36
        foreach ($field['bundles']['node'] as $type) {
37
          if (isset($data['actions']['output'][$type])) {
38
            $data['actions']['output'][$type]['#link']['title'] = t('Add new @node_type', array('@node_type' => i18n_node_type_name($type)));
39
          }
40
        }
41
      }
42
    }
43
  }
44
}
45

    
46
/**
47
 * Implements hook_form_FORM_ID_alter()
48
 */
49
function i18n_forum_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) {
50
  $vid = variable_get('forum_nav_vocabulary', 0);
51
  if ($vid && !isset($form_state['confirm_delete']) && isset($form['vid']) && $form['vid']['#value'] == $vid) {
52
    // Only two options for this vocabulary
53
    $replacements = array(
54
      '@item_name_multiple' => t('forum containers'),
55
      '@item_name_multiple_capitalized' => t('Forum containers'),
56
    );
57
    $form['i18n_translation']['i18n_mode']['#options'] = i18n_translation_options_list($replacements, array(I18N_MODE_LOCALIZE, I18N_MODE_TRANSLATE));
58
  }
59
}
60

    
61
/**
62
 * Implements hook_node_view().
63
 *
64
 * Localize breadcrumb for forum nodes.
65
 */
66
function i18n_forum_node_view($node, $view_mode, $langcode) {
67
  if (_forum_node_check_node_type($node)) {
68
    if ($view_mode == 'full' && node_is_page($node)) {
69
      $vid = variable_get('forum_nav_vocabulary', 0);
70
      $vocabulary = taxonomy_vocabulary_load($vid);
71
      // Breadcrumb navigation
72
      $breadcrumb[] = l(t('Home'), NULL);
73
      $breadcrumb[] = l(i18n_taxonomy_vocabulary_name($vocabulary), 'forum');
74
      if ($parents = taxonomy_get_parents_all($node->forum_tid)) {
75
        $parents = array_reverse($parents);
76
        foreach ($parents as $parent) {
77
          $breadcrumb[] = l(i18n_taxonomy_term_name($parent), 'forum/' . $parent->tid);
78
        }
79
      }
80
      drupal_set_breadcrumb($breadcrumb);
81
    }
82
  }
83
}
84

    
85
/**
86
 * Implements hook_i18n_translate_path()
87
 */
88
function i18n_forum_i18n_translate_path($path) {
89
  if (strpos($path, 'forum/') === 0 && i18n_forum_mode() & I18N_MODE_TRANSLATE) {
90
    return i18n_taxonomy_translate_path($path, 'forum/');
91
  }
92
}
93

    
94
/**
95
 * Translate forums list.
96
 */
97
function i18n_forum_preprocess_forum_list(&$variables) {
98
  if (i18n_forum_mode() & I18N_MODE_LOCALIZE) {
99
    foreach ($variables['forums'] as $id => $forum) {
100
      $variables['forums'][$id]->description = i18n_string('taxonomy:term:' . $forum->tid . ':description', $forum->description);
101
      $variables['forums'][$id]->name = i18n_string('taxonomy:term:' . $forum->tid . ':name', $forum->name);
102
    }
103
  }
104
}
105

    
106

    
107
/**
108
 * Translate forum page.
109
 */
110
function i18n_forum_preprocess_forums(&$variables) {
111
  if (i18n_forum_mode()) {
112
    $vocabulary = i18n_forum_vocabulary();
113
    if (isset($variables['links']['forum'])) {
114
      $variables['links']['forum']['title'] = i18n_string('nodetype:type:forum:post_button', 'Post new Forum topic');
115
    }
116
    // This one is from advanced forum, http://drupal.org/project/advanced_forum
117
    if (!empty($variables['forum_description'])) {
118
      $variables['forum_description'] = i18n_string('taxonomy:term:' . $variables['tid'] . ':description', $variables['forum_description']);
119
    }
120
    // Translate breadrumb and page title.
121
    $title = $vocabulary_name = !empty($vocabulary->name) ? i18n_taxonomy_vocabulary_name($vocabulary) : '';
122
    $breadcrumb[] = l(t('Home'), NULL);
123
    if ($variables['tid']) {
124
      $breadcrumb[] = l($vocabulary_name, 'forum');
125
    }
126
    if ($variables['parents']) {
127
      $variables['parents'] = array_reverse($variables['parents']);
128
      foreach ($variables['parents'] as $p) {
129
        if ($p->tid == $variables['tid']) {
130
          $title = i18n_taxonomy_term_name($p);
131
        }
132
        else {
133
          $breadcrumb[] = l(i18n_taxonomy_term_name($p), 'forum/' . $p->tid);
134
        }
135
      }
136
    }
137
    drupal_set_breadcrumb($breadcrumb);
138
    drupal_set_title($title);
139
  }
140
}
141

    
142
/**
143
 * Get forum vocabulary.
144
 */
145
function i18n_forum_vocabulary() {
146
  if ($vid = variable_get('forum_nav_vocabulary', 0)) {
147
    return taxonomy_vocabulary_load($vid);
148
  }
149
  else {
150
    return NULL;
151
  }
152
}
153

    
154
/**
155
 * Get forum vocabulary translation mode.
156
 */
157
function i18n_forum_mode($mode = NULL) {
158
  if ($vocabulary = i18n_forum_vocabulary()) {
159
    return i18n_taxonomy_vocabulary_mode($vocabulary);
160
  }
161
  else {
162
    return I18N_MODE_NONE;
163
  }
164
}