1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Internationalization (i18n) module - Translation set
|
5 |
|
|
*/
|
6 |
|
|
class i18n_path_translation_set extends i18n_translation_set {
|
7 |
|
|
/**
|
8 |
|
|
* Add translation item
|
9 |
|
|
*/
|
10 |
|
|
public function add_item($path, $langcode = NULL) {
|
11 |
|
|
// Path may be object or plain string
|
12 |
|
|
$item = is_object($path) ? $path : (object)array('path' => $path, 'language' => $langcode);
|
13 |
|
|
return parent::add_item($item, $langcode);
|
14 |
|
|
}
|
15 |
|
|
/**
|
16 |
|
|
* Clean path translations.
|
17 |
|
|
*
|
18 |
|
|
* Unlike other translation sets this actually deletes paths
|
19 |
|
|
*/
|
20 |
|
|
public function clean_translations() {
|
21 |
|
|
$delete = db_delete('i18n_path')
|
22 |
|
|
->condition('tsid', $this->tsid)
|
23 |
|
|
->condition('language', array_keys($this->get_translations()), 'NOT IN')
|
24 |
|
|
->execute();
|
25 |
|
|
}
|
26 |
|
|
/**
|
27 |
|
|
* Delete translation set
|
28 |
|
|
*/
|
29 |
|
|
public function delete_translations() {
|
30 |
|
|
return db_delete('i18n_path')
|
31 |
|
|
->condition('tsid', $this->tsid)
|
32 |
|
|
->execute();
|
33 |
|
|
}
|
34 |
|
|
/**
|
35 |
|
|
* Save all path translations
|
36 |
|
|
*/
|
37 |
|
|
public function save_translations() {
|
38 |
|
|
foreach ($this->get_translations() as $lang => $path) {
|
39 |
|
|
$path = is_object($path) ? $path : (object) array('path' => $path, 'language' => $lang, 'tsid' => $this->tsid);
|
40 |
|
|
drupal_write_record('i18n_path', $path, !empty($path->tpid) ? 'tpid' : array());
|
41 |
|
|
$this->add_item($path, $lang);
|
42 |
|
|
}
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
/**
|
48 |
|
|
* Path object
|
49 |
|
|
*/
|
50 |
|
|
class i18n_path_object extends i18n_object_wrapper {
|
51 |
|
|
/**
|
52 |
|
|
* Get title from item
|
53 |
|
|
*/
|
54 |
|
|
public function get_title() {
|
55 |
|
|
return $this->object->path;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
/**
|
59 |
|
|
* Get path for item
|
60 |
|
|
*/
|
61 |
|
|
public function get_path() {
|
62 |
|
|
return check_url($this->object->path);
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Get translate mode
|
67 |
|
|
*/
|
68 |
|
|
public function get_translate_mode() {
|
69 |
|
|
return I18N_MODE_TRANSLATE;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
} |