-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathtranslate.php
More file actions
157 lines (145 loc) · 6.38 KB
/
Copy pathtranslate.php
File metadata and controls
157 lines (145 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
if (!defined('W2P_BASE_DIR')) {
die('You should not access this file directly.');
}
// check permissions
$perms = &$AppUI->acl();
if (!canEdit('system')) {
$AppUI->redirect(ACCESS_DENIED);
}
$module = w2PgetParam($_REQUEST, 'module', 'admin');
$lang = w2PgetParam($_REQUEST, 'lang', $AppUI->user_locale);
// read the installed modules
$loader = new w2p_FileSystem_Loader();
$modules = arrayMerge($loader->readDirs('modules'), array('common' => 'common', 'styles' => 'styles'));
asort($modules);
// read the installed languages
$locales = $loader->readDirs('locales');
ob_start();
// read language files from module's locale directory preferably
$localeFile = W2P_BASE_DIR . '/modules/' . $modules[$module] . '/locales/en/' . $modules[$module] . '.inc';
if (file_exists($localeFile)) {
readfile($localeFile);
} else {
$localeFile = W2P_BASE_DIR . '/locales/en/' . $modules[$module] . '.inc';
if (file_exists($localeFile)) {
readfile($localeFile);
}
}
eval("\$english=array(" . ob_get_contents() . "\n'0');");
ob_end_clean();
$trans = array();
foreach ($english as $k => $v) {
if ($v != '0') {
$trans[(is_int($k) ? $v : $k)] = array('english' => $v);
}
}
if ($lang != 'en') {
ob_start();
// read language files from module's locale directory preferably
$localeFile = W2P_BASE_DIR . '/modules/' . $modules[$module] . '/locales/' . $lang . '/' . $modules[$module] . '.inc';
if (file_exists($localeFile)) {
readfile($localeFile);
} else {
$localeFile = W2P_BASE_DIR . '/locales/' . $lang . '/' . $modules[$module] . '.inc';
if (file_exists($localeFile)) {
readfile($localeFile);
}
}
eval("\$locale=array(" . ob_get_contents() . "\n'0');");
ob_end_clean();
foreach ($locale as $k => $v) {
if ($v != '0') {
$trans[$k]['lang'] = $v;
}
}
}
ksort($trans);
/**
* TODO: I don't like that this error is handled outside the normal flow but
* it's better than echo'ing which is what we had before.
*/
$localeFolder = pathinfo($localeFile, PATHINFO_DIRNAME);
if(file_exists($localeFile) && !is_writable($localeFile)) {
$AppUI->setMsg($AppUI->_("Locales file ($localeFile) is not writable."), UI_MSG_ERROR);
}
echo ('' != $AppUI->msg) ? $AppUI->getMsg() : '';
$titleBlock = new w2p_Theme_TitleBlock('Translation Management', 'rdf2.png', $m);
$titleBlock->addCell(' ', '', '<form action="?m=system&a=translate" method="post" name="modlang" accept-charset="utf-8">', '');
$titleBlock->addCell(arraySelect($modules, 'module', 'size="1" class="text" onchange="document.modlang.submit();"', $module));
$titleBlock->addCell($AppUI->_('Module'));
$temp = $AppUI->setWarning(false);
$titleBlock->addCell(arraySelect($locales, 'lang', 'size="1" class="text" onchange="document.modlang.submit();"', $lang, true), '', '', '</form>');
$titleBlock->addCell($AppUI->_('Language'));
$AppUI->setWarning($temp);
$titleBlock->addCrumb('?m=system', 'system admin');
$titleBlock->show();
?>
<form action="?m=system&a=translate_save" method="post" name="editlang" accept-charset="utf-8">
<input type="hidden" name="module" value="<?php echo $modules[$module]; ?>" />
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
<table class="tbl list">
<tr>
<th width="15%" nowrap="nowrap"><?php echo $AppUI->_('Abbreviation'); ?></th>
<th width="40%" nowrap="nowrap"><?php echo $AppUI->_('English String'); ?></th>
<th width="40%" nowrap="nowrap"><?php echo $AppUI->_('String') . ': ' . $AppUI->_($locales[$lang]); ?></th>
<th width="5%" nowrap="nowrap"><?php echo $AppUI->_('delete'); ?></th>
</tr>
<?php
$s = '';
$index = 0;
if ($lang == 'en') {
$s .= '<tr>';
$s .= '<td><input type="text" name="trans[' . $index . '][abbrev]" value="" size="20" class="text" /></td>';
$s .= '<td><input type="text" name="trans[' . $index . '][english]" value="" size="40" class="text" /></td>';
$s .= '<td colspan="2">' . $AppUI->_('New Entry') . '</td>';
$s .= '</tr>';
}
$index++;
foreach ($trans as $k => $langs) {
$s .= '<tr><td>';
if ($k != $langs['english']) {
$k = w2PformSafe($k, true);
if ($lang == 'en') {
$s .= '<input type="text" name="trans[' . $index . '][abbrev]" value="' . $k . '" size="20" class="text" />';
} else {
$s .= $k;
}
} else {
$s .= ' ';
}
$s .= '</td><td>';
$langs['english'] = w2PformSafe($langs['english'], true);
if ($lang == 'en') {
if (mb_strlen($langs['english']) < 40) {
$s .= '<input type="text" name="trans[' . $index . '][english]" value="' . $langs['english'] . '" size="40" class="text" />';
} else {
$rows = round(mb_strlen($langs['english'] / 35)) + 1;
$s .= '<textarea name="trans[' . $index . '][english]" cols="40" class="small" rows="' . $rows . '">' . $langs['english'] . '</textarea>';
}
} else {
$s .= $langs['english'];
$s .= '<input type="hidden" name="trans[' . $index . '][english]" value="' . ($k ? $k : $langs['english']) . '" size="20" class="text" />';
}
$s .= '</td><td>';
if ($lang != 'en') {
$langs['lang'] = w2PformSafe($langs['lang'], true);
if (mb_strlen($langs['lang']) < 40) {
$s .= '<input type="text" name="trans[' . $index . '][lang]" value="' . $langs['lang'] . '" size="40" class="text" />';
} else {
$rows = round(mb_strlen($langs['lang'] / 35)) + 1;
$s .= '<textarea name="trans[' . $index . '][lang]" cols="40" class="small" rows="' . $rows . '">' . $langs['lang'] . '</textarea>';
}
}
$s .= '</td><td align="center"><input type="checkbox" name="trans[' . $index . '][del]" /></td></tr>';
$index++;
}
echo $s;
?>
<tr>
<td colspan="4" align="right">
<input type="submit" value="<?php echo $AppUI->_('save'); ?>" class="save button btn btn-primary" />
</td>
</tr>
</table>
</form>