forked from LibreHealthIO/lh-ehr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslation.inc.php
323 lines (296 loc) · 9.4 KB
/
translation.inc.php
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?php
include_once(dirname(__FILE__) . '/sql.inc'); // fixes vulnerability with register_globals
require_once(dirname(__FILE__) . '/formdata.inc.php');
// Translation function
// This is the translation engine
// Note that it is recommended to no longer use the mode, prepend, or append
// parameters, since this is not compatible with the htmlspecialchars() php
// function.
function xl($constant,$mode='r',$prepend='',$append='') {
// set language id
if (!empty($_SESSION['language_choice'])) {
$lang_id = $_SESSION['language_choice'];
}
else {
$lang_id = 1;
}
if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
// language id = 1, so no need to translate
// -- remove comments
$string = preg_replace('/\{\{.*\}\}/', '', $constant);
}
else {
// TRANSLATE
// first, clean lines
// convert new lines to spaces and remove windows end of lines
$patterns = array ('/\n/','/\r/');
$replace = array (' ','');
$constant = preg_replace($patterns, $replace, $constant);
// second, attempt translation
$sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
"lang_definitions.cons_id = lang_constants.cons_id WHERE " .
"lang_id=? AND constant_name = ? LIMIT 1";
$res = sqlStatementNoLog($sql,array($lang_id,$constant));
$row = SqlFetchArray($res);
$string = $row['definition'];
if ($string == '') { $string = "$constant"; }
// remove dangerous characters and remove comments
$patterns = array ('/\n/','/\r/','/"/',"/'/",'/\{\{.*\}\}/');
$replace = array (' ','','`','`','');
$string = preg_replace($patterns, $replace, $string);
}
$string = "$prepend" . "$string" . "$append";
if ($mode=='e') {
echo $string;
} else {
return $string;
}
}
// ----------- xl() function wrappers ------------------------------
//
// Use above xl() function the majority of time for translations. The
// below wrappers are only for specific situations in order to support
// granular control of translations in certain parts of LibreEHR.
// Wrappers:
// xl_list_label()
// xl_layout_label()
// xl_gacl_group()
// xl_form_title()
// xl_document_category()
// xl_appt_category()
//
// Added 5-09 by BM for translation of list labels (when applicable)
// Only translates if the $GLOBALS['translate_lists'] is set to true.
function xl_list_label($constant,$mode='r',$prepend='',$append='') {
if ($GLOBALS['translate_lists']) {
// TRANSLATE
if ($mode == "e") {
xl($constant,$mode,$prepend,$append);
}
else {
return xl($constant,$mode,$prepend,$append);
}
}
else {
// DO NOT TRANSLATE
if ($mode == "e") {
echo $prepend.$constant.$append;
}
else {
return $prepend.$constant.$append;
}
}
}
// Added 5-09 by BM for translation of layout labels (when applicable)
// Only translates if the $GLOBALS['translate_layout'] is set to true.
function xl_layout_label($constant,$mode='r',$prepend='',$append='') {
if ($GLOBALS['translate_layout']) {
// TRANSLATE
if ($mode == "e") {
xl($constant,$mode,$prepend,$append);
}
else {
return xl($constant,$mode,$prepend,$append);
}
}
else {
// DO NOT TRANSLATE
if ($mode == "e") {
echo $prepend.$constant.$append;
}
else {
return $prepend.$constant.$append;
}
}
}
// Added 6-2009 by BM for translation of access control group labels
// (when applicable)
// Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
function xl_gacl_group($constant,$mode='r',$prepend='',$append='') {
if ($GLOBALS['translate_gacl_groups']) {
// TRANSLATE
if ($mode == "e") {
xl($constant,$mode,$prepend,$append);
}
else {
return xl($constant,$mode,$prepend,$append);
}
}
else {
// DO NOT TRANSLATE
if ($mode == "e") {
echo $prepend.$constant.$append;
}
else {
return $prepend.$constant.$append;
}
}
}
// Added 6-2009 by BM for translation of patient form (notes) titles
// (when applicable)
// Only translates if the $GLOBALS['translate_form_titles'] is set to true.
function xl_form_title($constant,$mode='r',$prepend='',$append='') {
if ($GLOBALS['translate_form_titles']) {
// TRANSLATE
if ($mode == "e") {
xl($constant,$mode,$prepend,$append);
}
else {
return xl($constant,$mode,$prepend,$append);
}
}
else {
// DO NOT TRANSLATE
if ($mode == "e") {
echo $prepend.$constant.$append;
}
else {
return $prepend.$constant.$append;
}
}
}
//
// Added 6-2009 by BM for translation of document categories
// (when applicable)
// Only translates if the $GLOBALS['translate_document_categories'] is set to true.
function xl_document_category($constant,$mode='r',$prepend='',$append='') {
if ($GLOBALS['translate_document_categories']) {
// TRANSLATE
if ($mode == "e") {
xl($constant,$mode,$prepend,$append);
}
else {
return xl($constant,$mode,$prepend,$append);
}
}
else {
// DO NOT TRANSLATE
if ($mode == "e") {
echo $prepend.$constant.$append;
}
else {
return $prepend.$constant.$append;
}
}
}
//
// Added 6-2009 by BM for translation of appointment categories
// (when applicable)
// Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
function xl_appt_category($constant,$mode='r',$prepend='',$append='') {
if ($GLOBALS['translate_appt_categories']) {
// TRANSLATE
if ($mode == "e") {
xl($constant,$mode,$prepend,$append);
}
else {
return xl($constant,$mode,$prepend,$append);
}
}
else {
// DO NOT TRANSLATE
if ($mode == "e") {
echo $prepend.$constant.$append;
}
else {
return $prepend.$constant.$append;
}
}
}
// ---------------------------------------------------------------------------
// ---------------------------------
// Miscellaneous language translation functions
// Function to return the title of a language from the id
// @param integer (language id)
// return string (language title)
function getLanguageTitle($val) {
// validate language id
if (!empty($val)) {
$lang_id = $val;
}
else {
$lang_id = 1;
}
// get language title
$res = sqlStatement("select lang_description from lang_languages where lang_id =?",array($lang_id));
for ($iter = 0;$row = sqlFetchArray($res);$iter++) $result[$iter] = $row;
$languageTitle = $result[0]{"lang_description"};
return $languageTitle;
}
/**
* Returns language directionality as string 'rtl' or 'ltr'
* @param int $lang_id language code
* @return string 'ltr' 'rtl'
* @author Amiel <[email protected]>
*/
function getLanguageDir($lang_id) {
// validate language id
$lang_id = empty($lang_id) ? 1 : $lang_id;
// get language code
$row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
return !empty($row['lang_is_rtl']) ? 'rtl' : 'ltr';
}
//----------------------------------
// ----------------------------------------------------------------------------
/**
HEADER HTML
shows some informations for pages html header
@param none
@return void
*/
function html_header_show() {
// Below line was commented by the UTF-8 project on 05-2009 by BM.
// We commented this out since we are now standardizing encoding
// in the globals.php file.
// echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
}
// ----------------------------------------------------------------------------
/**
* Returns a string padded to a certain length with another string.
*
* This method behaves exactly like str_pad but is multibyte safe.
*
* @param string $input The string to be padded.
* @param int $length The length of the resulting string.
* @param string $pad The string to pad the input string with. Must
* be in the same charset like the input string.
* @param const $type The padding type. One of STR_PAD_LEFT,
* STR_PAD_RIGHT, or STR_PAD_BOTH.
* @param string $charset The charset of the input and the padding
* strings.
*
* @return string The padded string.
*/
function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT, $charset = 'UTF-8') {
mb_internal_encoding($charset);
$mb_length = mb_strlen($input, $charset);
$sb_length = strlen($input);
$pad_length = mb_strlen($pad, $charset);
/* Return if we already have the length. */
if ($mb_length >= $length) {
return $input;
}
/* Shortcut for single byte strings. */
if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
return str_pad($input, $length, $pad, $type);
}
switch ($type) {
case STR_PAD_LEFT:
$left = $length - $mb_length;
$output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
break;
case STR_PAD_BOTH:
$left = floor(($length - $mb_length) / 2);
$right = ceil(($length - $mb_length) / 2);
$output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
$input .
mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
break;
case STR_PAD_RIGHT:
$right = $length - $mb_length;
$output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
break;
}
return $output;
}
?>