|
1
|
|
|
<?php |
|
2
|
|
|
/* Requires this table: |
|
3
|
|
|
CREATE TABLE translation ( |
|
4
|
|
|
id int NOT NULL AUTO_INCREMENT, -- optional |
|
5
|
|
|
language_id varchar(5) NOT NULL, |
|
6
|
|
|
idf text NOT NULL COLLATE utf8_bin, |
|
7
|
|
|
translation text NOT NULL, |
|
8
|
|
|
UNIQUE (language_id, idf(100)), |
|
9
|
|
|
PRIMARY KEY (id) |
|
10
|
|
|
); |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** Translate all table and field comments, enum and set values from the translation table (inserts new translations) |
|
14
|
|
|
* @link https://www.adminer.org/plugins/#use |
|
15
|
|
|
* @author Jakub Vrana, http://www.vrana.cz/ |
|
16
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 |
|
17
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) |
|
18
|
|
|
*/ |
|
19
|
|
|
class AdminerTranslation { |
|
20
|
|
|
|
|
21
|
|
|
function _translate($idf) { |
|
|
|
|
|
|
22
|
|
|
static $translations, $lang; |
|
23
|
|
|
if ($lang === null) { |
|
24
|
|
|
$lang = get_lang(); |
|
25
|
|
|
} |
|
26
|
|
|
if ($idf == '' || $lang == 'en') { |
|
27
|
|
|
return $idf; |
|
28
|
|
|
} |
|
29
|
|
|
if ($translations === null) { |
|
30
|
|
|
$translations = get_key_vals('SELECT idf, translation FROM translation WHERE language_id = ' . q($lang)); |
|
31
|
|
|
} |
|
32
|
|
|
$return = &$translations[$idf]; |
|
33
|
|
|
if ($return === null) { |
|
34
|
|
|
$return = $idf; |
|
35
|
|
|
$connection = connection(); |
|
36
|
|
|
$connection->query('INSERT INTO translation (language_id, idf, translation) VALUES (' . q($lang) . ', ' . q($idf) . ', ' . q($idf) . ')'); |
|
37
|
|
|
} |
|
38
|
|
|
return $return; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function tableName(&$tableStatus) { |
|
|
|
|
|
|
42
|
|
|
$tableStatus['Comment'] = $this->_translate($tableStatus['Comment']); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
function fieldName(&$field, $order = 0) { |
|
|
|
|
|
|
46
|
|
|
$field['comment'] = $this->_translate($field['comment']); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function editVal(&$val, $field) { |
|
|
|
|
|
|
50
|
|
|
if ($field['type'] == 'enum') { |
|
51
|
|
|
$val = $this->_translate($val); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.