Projet

Général

Profil

Paste
Télécharger (3,17 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / i18n / i18n.pages.inc @ ba09eb79

1 85ad3d82 Assos Assos
<?php
2
/**
3
 * @file
4
 * Generic translation pages
5
 * 
6
 * It handles generic 'translation' tabs, redirecting to the right module depending on
7
 * object type and properties.
8
 */
9
10
/**
11
 * Create menu items for translatable objecs
12
 */
13
function i18n_page_menu_items() {
14
  $items = array();
15
  // Menus are rebuilt right after other modules are disabled, if no reset we get tabs for disabled modules.
16
  drupal_static_reset('i18n_object_info');
17
  foreach (i18n_object_info() as $type => $info) {
18
    // These objects should have a 'translate tab' property
19
    if (!empty($info['translate tab'])) {
20
      $path = $info['translate tab'];
21
      $localize = module_exists('i18n_string') && !empty($info['string translation']);
22
      $translate = module_exists('i18n_translation') && i18n_translation_set_info($type);
23
      if ($translate && $localize) {
24
        $page_callback = 'i18n_page_translate_tab';
25
      }
26
      elseif ($translate) {
27
        $page_callback = 'i18n_page_translate_translation';
28
      }
29
      elseif ($localize) {
30
        $page_callback = 'i18n_page_translate_localize';
31
      }
32
      // Find the position for the object placeholder. We assume the first one.
33
      $placeholder = key($info['placeholders']);
34
      $parts = explode('/', $path);
35
      $position = array_search($placeholder, $parts);
36
      // Now create items with the right callbacks
37
      if ($translate || $localize) {
38
        $items[$path] = array(
39
          'title' => 'Translate',
40
          'page callback' => $page_callback,
41
          'page arguments' => array($type, $position),
42
          'access callback' => 'i18n_object_translate_access',
43
          'access arguments' => array($type, $position),
44
          'type' => MENU_LOCAL_TASK,
45
          'file' => 'i18n.pages.inc',
46
          'weight' => 10,
47
        );
48
      }
49
      if ($localize) {
50
        $items[$path . '/%i18n_language'] = array(
51
          'title' => 'Translate',
52
          'page callback' => $page_callback,
53
          'page arguments' => array($type, $position, count($parts)),
54
          'access callback' => 'i18n_object_translate_access',
55
          'access arguments' => array($type, $position),
56
          'type' => MENU_CALLBACK,
57
          'file' => 'i18n.pages.inc',
58
        );
59
      }
60
    }
61
    
62
  }
63
  return $items;
64
}
65
66
/**
67
 * Translate or localize page for object
68
 */
69
function i18n_page_translate_tab($type, $object, $language = NULL) {
70
   // Check whether object should be part of a translation set
71
   switch (i18n_object($type, $object)->get_translate_mode()) {
72
     case I18N_MODE_TRANSLATE:
73
       return i18n_page_translate_translation($type, $object);
74
     case I18N_MODE_LOCALIZE:
75
       return i18n_page_translate_localize($type, $object, $language);
76
     default:
77
       drupal_access_denied();
78
   }
79
}
80
81
/**
82
 * Translate object, create translation set
83
 */
84
function i18n_page_translate_translation($type, $object) {
85
  module_load_include('pages.inc', 'i18n_translation');
86
  return i18n_translation_object_translate_page($type, $object);
87
}
88
89
/**
90
 * Translate object, string translation
91
 */
92
function i18n_page_translate_localize($type, $object, $language = NULL) {
93
  module_load_include('pages.inc', 'i18n_string');
94
  return i18n_string_object_translate_page($type, $object, $language);
95
}