Issues #1214616 and #1156564: Taxonomy term translation issues and Remove term from...
[project/i18n.git] / i18n.pages.inc
1 <?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 foreach (i18n_object_info() as $type => $info) {
16 // These objects should have a 'translate tab' property
17 if (!empty($info['translate tab'])) {
18 $path = $info['translate tab'];
19 $localize = module_exists('i18n_string') && !empty($info['string translation']);
20 $translate = module_exists('i18n_translation') && !empty($info['translation set']);
21 if ($translate && $localize) {
22 $page_callback = 'i18n_page_translate_tab';
23 }
24 elseif ($translate) {
25 $page_callback = 'i18n_page_translate_translation';
26 }
27 elseif ($localize) {
28 $page_callback = 'i18n_page_translate_localize';
29 }
30 // Find the position for the object placeholder. We assume the first one.
31 $placeholder = key($info['placeholders']);
32 $parts = explode('/', $path);
33 $position = array_search($placeholder, $parts);
34 // Now create items with the right callbacks
35 if ($translate || $localize) {
36 $items[$path] = array(
37 'title' => 'Translate',
38 'page callback' => $page_callback,
39 'page arguments' => array($type, $position),
40 'access callback' => 'i18n_object_translate_access',
41 'access arguments' => array($type, $position),
42 'type' => MENU_LOCAL_TASK,
43 'file' => 'i18n.pages.inc',
44 'weight' => 10,
45 );
46 }
47 if ($localize) {
48 $items[$path . '/%language'] = array(
49 'title' => 'Translate',
50 'page callback' => $page_callback,
51 'page arguments' => array($type, $position, count($parts)),
52 'access callback' => 'i18n_object_translate_access',
53 'access arguments' => array($type, $position),
54 'type' => MENU_CALLBACK,
55 'field' => 'i18n.pages.inc',
56 );
57 }
58 }
59
60 }
61 return $items;
62 }
63
64 /**
65 * Translate or localize page for object
66 */
67 function i18n_page_translate_tab($type, $object, $language = NULL) {
68 // Check whether object should be part of a translation set
69 switch (i18n_object($type, $object)->get_translate_mode()) {
70 case I18N_MODE_TRANSLATE:
71 return i18n_page_translate_translation($type, $object);
72 case I18N_MODE_LOCALIZE:
73 return i18n_page_translate_localize($type, $object, $language);
74 default:
75 drupal_access_denied();
76 }
77 }
78
79 /**
80 * Translate object, create translation set
81 */
82 function i18n_page_translate_translation($type, $object) {
83 module_load_include('pages.inc', 'i18n_translation');
84 return i18n_translation_object_translate_page($type, $object);
85 }
86
87 /**
88 * Translate object, string translation
89 */
90 function i18n_page_translate_localize($type, $object, $language = NULL) {
91 module_load_include('pages.inc', 'i18n_string');
92 return i18n_string_object_translate_page($type, $object, $language);
93 }