1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Internationalization (i18n) module - Path translation
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_menu()
|
10
|
*/
|
11
|
function i18n_path_menu() {
|
12
|
$items['admin/config/regional/i18n_translation/path'] = array(
|
13
|
'title' => 'Paths',
|
14
|
'description' => 'Path translation.',
|
15
|
'page callback' => 'i18n_path_admin_overview',
|
16
|
'access arguments' => array('administer site configuration'),
|
17
|
'file' => 'i18n_path.admin.inc',
|
18
|
'type' => MENU_LOCAL_TASK,
|
19
|
'weight' => 10,
|
20
|
);
|
21
|
$items['admin/config/regional/i18n_translation/path/list'] = array(
|
22
|
'title' => 'Paths',
|
23
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
24
|
'weight' => -10,
|
25
|
);
|
26
|
$items['admin/config/regional/i18n_translation/path/add'] = array(
|
27
|
'title' => 'Add path translation',
|
28
|
'page callback' => 'drupal_get_form',
|
29
|
'page arguments' => array('i18n_path_admin_form'),
|
30
|
'access arguments' => array('administer site configuration'),
|
31
|
'file' => 'i18n_path.admin.inc',
|
32
|
'type' => MENU_LOCAL_ACTION,
|
33
|
'parent' => 'admin/config/regional/i18n_translation',
|
34
|
);
|
35
|
$items['admin/config/regional/i18n_translation/path/edit/%i18n_path_translation_set'] = array(
|
36
|
'title' => 'Edit path translation',
|
37
|
'page callback' => 'drupal_get_form',
|
38
|
'page arguments' => array('i18n_path_admin_form', 6),
|
39
|
'access arguments' => array('administer site configuration'),
|
40
|
'file' => 'i18n_path.admin.inc',
|
41
|
'type' => MENU_LOCAL_TASK,
|
42
|
'context' => MENU_CONTEXT_INLINE,
|
43
|
);
|
44
|
$items['admin/config/regional/i18n_translation/path/delete/%i18n_path_translation_set'] = array(
|
45
|
'title' => 'Delete path translation',
|
46
|
'page callback' => 'drupal_get_form',
|
47
|
'page arguments' => array('i18n_translation_set_delete_confirm', 6),
|
48
|
'access arguments' => array('administer site configuration'),
|
49
|
'file' => 'i18n_path.admin.inc',
|
50
|
'type' => MENU_LOCAL_TASK,
|
51
|
'context' => MENU_CONTEXT_INLINE,
|
52
|
);
|
53
|
return $items;
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* Implements hook_url_outbound_alter()
|
58
|
*/
|
59
|
/*
|
60
|
function i18n_path_url_outbound_alter(&$path, &$options, $original_path) {
|
61
|
if (!empty($options['language'])) {
|
62
|
$langcode = $options['language']->language;
|
63
|
$original = $options['alias'] ? drupal_get_normal_path($path, $langcode) : $original_path;
|
64
|
if (($translations = i18n_path_get_translations($path)) && !empty($translations[$langcode])) {
|
65
|
$path = $options['alias'] ? drupal_get_path_alias($translations[$langcode], $langcode) : $translations[$langcode];
|
66
|
}
|
67
|
}
|
68
|
}
|
69
|
*/
|
70
|
|
71
|
/**
|
72
|
* Get translations for path
|
73
|
*/
|
74
|
function i18n_path_get_translations($path) {
|
75
|
static $translations;
|
76
|
|
77
|
if (!isset($translations)) {
|
78
|
$translations = drupal_static(__FUNCTION__, array());
|
79
|
}
|
80
|
if (!isset($translations[$path])) {
|
81
|
$translations[$path] = db_query('SELECT p.language, p.path FROM {i18n_path} p INNER JOIN {i18n_path} ps ON p.tsid = ps.tsid WHERE ps.path = :path',
|
82
|
array(':path' => $path)
|
83
|
)->fetchAllKeyed();
|
84
|
}
|
85
|
return $translations[$path];
|
86
|
}
|
87
|
|
88
|
|
89
|
/**
|
90
|
* Implements hook_i18n_object_info().
|
91
|
*/
|
92
|
function i18n_path_i18n_object_info() {
|
93
|
return array(
|
94
|
'path' => array(
|
95
|
'title' => t('Path'),
|
96
|
'class' => 'i18n_path_object',
|
97
|
'key' => array('path', 'language'),
|
98
|
'translation set' => TRUE,
|
99
|
)
|
100
|
);
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* Implements hook_i18n_translation_set_info()
|
105
|
*/
|
106
|
function i18n_path_i18n_translation_set_info() {
|
107
|
return array(
|
108
|
'path' => array(
|
109
|
'title' => t('Path'),
|
110
|
'class' => 'i18n_path_translation_set',
|
111
|
'table' => 'i18n_path',
|
112
|
'field' => 'tsid',
|
113
|
'placeholder' => '%i18n_path_translation_set',
|
114
|
'edit path' => 'admin/config/regional/i18n_translation/path/edit/%i18n_path_translation_set',
|
115
|
'delete path' => 'admin/config/regional/i18n_translation/path/delete/%i18n_path_translation_set',
|
116
|
'list path' => 'admin/config/regional/i18n_translation/path',
|
117
|
),
|
118
|
);
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* Implements hook_i18n_translate_path()
|
123
|
*/
|
124
|
function i18n_path_i18n_translate_path($path) {
|
125
|
if ($translations = i18n_path_get_translations($path)) {
|
126
|
$result = array();
|
127
|
foreach ($translations as $langcode => $translated) {
|
128
|
$result[$langcode] = array(
|
129
|
'href' => $translated,
|
130
|
);
|
131
|
}
|
132
|
return $result;
|
133
|
}
|
134
|
}
|
135
|
|
136
|
/**
|
137
|
* Load translation set. Menu loading callback.
|
138
|
*/
|
139
|
function i18n_path_translation_set_load($tsid) {
|
140
|
return i18n_translation_set_load($tsid, 'path');
|
141
|
}
|