3 // Translation function
4 // This is the translation engine
5 // Note that it is recommended to no longer use the mode, prepend, or append
6 // parameters, since this is not compatible with the htmlspecialchars() php
9 // Note there are cases in installation where this function has already been
10 // declared, so check to ensure has not been declared yet.
12 if (!(function_exists('xl'))) {
13 function xl($constant,$mode='r',$prepend='',$append='')
16 if (!empty($_SESSION['language_choice'])) {
17 $lang_id = $_SESSION['language_choice'];
23 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
24 // language id = 1, so no need to translate
26 $string = preg_replace('/\{\{.*\}\}/', '', $constant);
31 // convert new lines to spaces and remove windows end of lines
32 $patterns = array ('/\n/','/\r/');
33 $replace = array (' ','');
34 $constant = preg_replace($patterns, $replace, $constant);
36 // second, attempt translation
37 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
38 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
39 "lang_id=? AND constant_name = ? LIMIT 1";
40 $res = sqlStatementNoLog($sql,array($lang_id,$constant));
41 $row = SqlFetchArray($res);
42 $string = $row['definition'];
43 if ($string == '') { $string = "$constant"; }
45 // remove dangerous characters and remove comments
46 if ($GLOBALS['translate_no_safe_apostrophe']) {
47 $patterns = array ('/\n/','/\r/','/\{\{.*\}\}/');
48 $replace = array (' ','','');
49 $string = preg_replace($patterns, $replace, $string);
52 // convert apostrophes and quotes to safe apostrophe
53 $patterns = array ('/\n/','/\r/','/"/',"/'/",'/\{\{.*\}\}/');
54 $replace = array (' ','','`','`','');
55 $string = preg_replace($patterns, $replace, $string);
59 $string = "$prepend" . "$string" . "$append";
68 // ----------- xl() function wrappers ------------------------------
70 // Use above xl() function the majority of time for translations. The
71 // below wrappers are only for specific situations in order to support
72 // granular control of translations in certain parts of OpenEMR.
78 // xl_document_category()
81 // Added 5-09 by BM for translation of list labels (when applicable)
82 // Only translates if the $GLOBALS['translate_lists'] is set to true.
83 function xl_list_label($constant,$mode='r',$prepend='',$append='')
85 if ($GLOBALS['translate_lists']) {
88 xl($constant,$mode,$prepend,$append);
91 return xl($constant,$mode,$prepend,$append);
97 echo $prepend.$constant.$append;
100 return $prepend.$constant.$append;
104 // Added 5-09 by BM for translation of layout labels (when applicable)
105 // Only translates if the $GLOBALS['translate_layout'] is set to true.
106 function xl_layout_label($constant,$mode='r',$prepend='',$append='')
108 if ($GLOBALS['translate_layout']) {
111 xl($constant,$mode,$prepend,$append);
114 return xl($constant,$mode,$prepend,$append);
120 echo $prepend.$constant.$append;
123 return $prepend.$constant.$append;
127 // Added 6-2009 by BM for translation of access control group labels
129 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
130 function xl_gacl_group($constant,$mode='r',$prepend='',$append='')
132 if ($GLOBALS['translate_gacl_groups']) {
135 xl($constant,$mode,$prepend,$append);
138 return xl($constant,$mode,$prepend,$append);
144 echo $prepend.$constant.$append;
147 return $prepend.$constant.$append;
151 // Added 6-2009 by BM for translation of patient form (notes) titles
153 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
154 function xl_form_title($constant,$mode='r',$prepend='',$append='')
156 if ($GLOBALS['translate_form_titles']) {
159 xl($constant,$mode,$prepend,$append);
162 return xl($constant,$mode,$prepend,$append);
168 echo $prepend.$constant.$append;
171 return $prepend.$constant.$append;
176 // Added 6-2009 by BM for translation of document categories
178 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
179 function xl_document_category($constant,$mode='r',$prepend='',$append='')
181 if ($GLOBALS['translate_document_categories']) {
184 xl($constant,$mode,$prepend,$append);
187 return xl($constant,$mode,$prepend,$append);
193 echo $prepend.$constant.$append;
196 return $prepend.$constant.$append;
201 // Added 6-2009 by BM for translation of appointment categories
203 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
204 function xl_appt_category($constant,$mode='r',$prepend='',$append='')
206 if ($GLOBALS['translate_appt_categories']) {
209 xl($constant,$mode,$prepend,$append);
212 return xl($constant,$mode,$prepend,$append);
218 echo $prepend.$constant.$append;
221 return $prepend.$constant.$append;
225 // ---------------------------------------------------------------------------
227 // ---------------------------------
228 // Miscellaneous language translation functions
230 // Function to return the title of a language from the id
231 // @param integer (language id)
232 // return string (language title)
233 function getLanguageTitle($val)
236 // validate language id
244 // get language title
245 $res = sqlStatement("select lang_description from lang_languages where lang_id =?",array($lang_id));
246 for ($iter = 0;$row = sqlFetchArray($res);
247 $iter++
) $result[$iter] = $row;
248 $languageTitle = $result[0]{"lang_description"};
249 return $languageTitle;
256 * Returns language directionality as string 'rtl' or 'ltr'
257 * @param int $lang_id language code
258 * @return string 'ltr' 'rtl'
259 * @author Amiel <amielel@matrix.co.il>
261 function getLanguageDir($lang_id)
263 // validate language id
264 $lang_id = empty($lang_id) ?
1 : $lang_id;
266 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
268 return !empty($row['lang_is_rtl']) ?
'rtl' : 'ltr';
271 //----------------------------------
273 // ----------------------------------------------------------------------------
277 shows some informations for pages html header
282 function html_header_show()
285 // Below line was commented by the UTF-8 project on 05-2009 by BM.
286 // We commented this out since we are now standardizing encoding
287 // in the globals.php file.
288 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
290 // Keeping this function, since it may prove useful for user interface improvements