1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Internationalization (i18n) module - Translation set
|
5 |
|
|
*/
|
6 |
|
|
class i18n_menu_link_translation_set extends i18n_translation_set {
|
7 |
|
|
/**
|
8 |
|
|
* Load all path translations
|
9 |
|
|
*/
|
10 |
|
|
public function load_translations() {
|
11 |
|
|
$translations = array();
|
12 |
|
|
$query = db_select('menu_links', 'ml');
|
13 |
|
|
$query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
|
14 |
|
|
$query->fields('ml');
|
15 |
|
|
// Weight should be taken from {menu_links}, not {menu_router}.
|
16 |
|
|
$query->addField('ml', 'weight', 'link_weight');
|
17 |
|
|
$query->fields('m');
|
18 |
|
|
$query->condition('ml.i18n_tsid', $this->tsid);
|
19 |
|
|
foreach ($query->execute()->fetchAll(PDO::FETCH_ASSOC) as $item) {
|
20 |
|
|
$item['weight'] = $item['link_weight'];
|
21 |
|
|
_menu_link_translate($item);
|
22 |
|
|
$translations[$item['language']] = $item;
|
23 |
|
|
}
|
24 |
|
|
return $translations;
|
25 |
|
|
}
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
/**
|
29 |
|
|
* Menu link object
|
30 |
|
|
*/
|
31 |
|
|
class i18n_menu_link extends i18n_string_object_wrapper {
|
32 |
|
|
/**
|
33 |
|
|
* Class constructor
|
34 |
|
|
*/
|
35 |
|
|
public function __construct($type, $key, $object) {
|
36 |
|
|
// Unserialize options if not done
|
37 |
|
|
if (isset($object['options']) && !is_array($object['options'])) {
|
38 |
|
|
$object['options'] = unserialize($object['options']);
|
39 |
|
|
}
|
40 |
|
|
parent::__construct($type, $key, $object);
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
/**
|
44 |
|
|
* Get path for item
|
45 |
|
|
*/
|
46 |
|
|
public function get_path() {
|
47 |
|
|
return $this->object['link_path'];
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
/**
|
51 |
|
|
* Get title from item
|
52 |
|
|
*/
|
53 |
|
|
public function get_title() {
|
54 |
|
|
return $this->object['title'];
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* Translation mode for object
|
59 |
|
|
*/
|
60 |
|
|
public function get_translate_mode() {
|
61 |
|
|
$mode = i18n_menu_mode($this->object['menu_name']);
|
62 |
|
|
if ($this->get_langcode()) {
|
63 |
|
|
return $mode & I18N_MODE_TRANSLATE;
|
64 |
|
|
}
|
65 |
|
|
elseif (!empty($this->object['customized'])) {
|
66 |
|
|
return $mode & I18N_MODE_LOCALIZE;
|
67 |
|
|
}
|
68 |
|
|
else {
|
69 |
|
|
return I18N_MODE_NONE;
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
/**
|
74 |
|
|
* Access to object translation. This should check object properties and permissions
|
75 |
|
|
*/
|
76 |
|
|
protected function translate_access() {
|
77 |
|
|
return user_access('administer menu') && user_access('translate interface');
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
/**
|
81 |
|
|
* Get translatable properties.
|
82 |
|
|
*
|
83 |
|
|
* Check whether title or description are to be translated by default menu
|
84 |
|
|
* system.
|
85 |
|
|
*/
|
86 |
|
|
protected function build_properties() {
|
87 |
|
|
$properties = parent::build_properties();
|
88 |
|
|
if ($properties) {
|
89 |
|
|
$strings = &$properties['menu']['item'][$this->get_key()];
|
90 |
|
|
$localizable = _i18n_menu_link_localizable_properties($this->object);
|
91 |
|
|
foreach ($strings as $key => $data) {
|
92 |
|
|
if (!in_array($key, $localizable)) {
|
93 |
|
|
unset($strings[$key]);
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
}
|
97 |
|
|
return $properties;
|
98 |
|
|
}
|
99 |
|
|
} |