summaryrefslogtreecommitdiffstats
path: root/i18n_forum/i18n_forum.module
blob: b3d79812b439d158b61a3159874a2a43c304d812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php

/**
 * @file
 * i18n forum module
 *
 * Internationalization (i18n) package.
 */

/**
 * Implements hook_help().
 */
function i18n_forum_help($path, $arg) {
  if ($path == 'admin/structure/forum') {
    $vid = variable_get('forum_nav_vocabulary', 0);
    $vocabulary = taxonomy_vocabulary_load($vid);
    $name = $vocabulary->machine_name;
    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('@edit' => url('admin/structure/taxonomy/' . $name . '/edit'), '@translate' => url('admin/structure/taxonomy/' . $name . '/translate'), '@list' => url('admin/structure/taxonomy/' . $name . '/list')));
  }
}

/**
 * Implements hook_menu_local_tasks_alter().
 */
function i18n_forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  // Translate link to 'node/add/forum' on 'forum' sub-pages.
  if ($root_path == 'forum' || $root_path == 'forum/%') {
    $tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->tid : 0);
    $forum_term = forum_forum_load($tid);
    if ($forum_term) {
      // Loop through all bundles for forum taxonomy vocabulary field.
      $vid = variable_get('forum_nav_vocabulary', 0);
      if ($vid && ($vocabulary = taxonomy_vocabulary_load($vid)) && ($field = field_info_field('taxonomy_' . $vocabulary->machine_name))) {
        foreach ($field['bundles']['node'] as $type) {
          if (isset($data['actions']['output'][$type])) {
            $data['actions']['output'][$type]['#link']['title'] = t('Add new @node_type', array('@node_type' => i18n_node_type_name($type, node_type_get_name($type))));
          }
        }
      }
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter()
 */
function i18n_forum_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) {
  $vid = variable_get('forum_nav_vocabulary', 0);
  if ($vid && !isset($form_state['confirm_delete']) && isset($form['vid']) && $form['vid']['#value'] == $vid) {
    // Only two options for this vocabulary
    $replacements = array(
    	'@item_name_multiple' => t('forum containers'),
    	'@item_name_multiple_capitalized' => t('Forum containers'),
    );
    $form['i18n_translation']['i18n_mode']['#options'] = i18n_translation_options_list($replacements, array(I18N_MODE_LOCALIZE, I18N_MODE_TRANSLATE));
  }
}

/**
 * Implements hook_node_view().
 *
 * Localize breadcrumb for forum nodes.
 */
function i18n_forum_node_view($node, $view_mode, $langcode) {
  if (_forum_node_check_node_type($node)) {
    if ($view_mode == 'full' && node_is_page($node)) {
      $vid = variable_get('forum_nav_vocabulary', 0);
      $vocabulary = taxonomy_vocabulary_load($vid);
      // Breadcrumb navigation
      $breadcrumb[] = l(t('Home'), NULL);
      $breadcrumb[] = l(i18n_taxonomy_vocabulary_name($vocabulary), 'forum');
      if ($parents = taxonomy_get_parents_all($node->forum_tid)) {
        $parents = array_reverse($parents);
        foreach ($parents as $parent) {
          $breadcrumb[] = l(i18n_taxonomy_term_name($parent), 'forum/' . $parent->tid);
        }
      }
      drupal_set_breadcrumb($breadcrumb);
    }
  }
}

/**
 * Translate forums list.
 */
function i18n_forum_preprocess_forum_list(&$variables) {
  $vid = variable_get('forum_nav_vocabulary', 0);
  if (i18n_taxonomy_vocabulary_mode($vid)) {
    foreach ($variables['forums'] as $id => $forum) {
      $variables['forums'][$id]->description = i18n_string('taxonomy:term:'. $forum->tid .':description', $forum->description);
      $variables['forums'][$id]->name = i18n_string('taxonomy:term:'. $forum->tid .':name', $forum->name);
    }
  }
}


/**
 * Translate forum page.
 */
function i18n_forum_preprocess_forums(&$variables) {
  $vid = variable_get('forum_nav_vocabulary', 0);
  if (i18n_taxonomy_vocabulary_mode($vid)) {
    if (isset($variables['links']['forum'])) {
      $variables['links']['forum']['title'] = i18n_string('nodetype:type:forum:post_button', 'Post new Forum topic');
    }
    // This one is from advanced forum, http://drupal.org/project/advanced_forum
    if (!empty($variables['forum_description'])) {
      $variables['forum_description'] = i18n_string('taxonomy:term:'. $variables['tid'] .':description', $variables['forum_description']);
    }
    $vocabulary = taxonomy_vocabulary_load($vid);
    // Translate breadrumb and page title.
    $title = $vocabulary_name = !empty($vocabulary->name) ? i18n_taxonomy_vocabulary_name($vocabulary) : '';
    $breadcrumb[] = l(t('Home'), NULL);
    if ($variables['tid']) {
      $breadcrumb[] = l($vocabulary_name, 'forum');
    }
    if ($variables['parents']) {
      $variables['parents'] = array_reverse($variables['parents']);
      foreach ($variables['parents'] as $p) {
        if ($p->tid == $variables['tid']) {
          $title = i18n_taxonomy_term_name($p);
        }
        else {
          $breadcrumb[] = l(i18n_taxonomy_term_name($p), 'forum/' . $p->tid);
        }
      }
    }
    drupal_set_breadcrumb($breadcrumb);
    drupal_set_title($title);
  }
}