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='') {
15 if (!empty($_SESSION['language_choice'])) {
16 $lang_id = $_SESSION['language_choice'];
22 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
23 // language id = 1, so no need to translate
25 $string = preg_replace('/\{\{.*\}\}/', '', $constant);
30 // convert new lines to spaces and remove windows end of lines
31 $patterns = array ('/\n/','/\r/');
32 $replace = array (' ','');
33 $constant = preg_replace($patterns, $replace, $constant);
35 // second, attempt translation
36 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
37 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
38 "lang_id=? AND constant_name = ? LIMIT 1";
39 $res = sqlStatementNoLog($sql,array($lang_id,$constant));
40 $row = SqlFetchArray($res);
41 $string = $row['definition'];
42 if ($string == '') { $string = "$constant"; }
44 // remove dangerous characters and remove comments
45 $patterns = array ('/\n/','/\r/','/"/',"/'/",'/\{\{.*\}\}/');
46 $replace = array (' ','','`','`','');
47 $string = preg_replace($patterns, $replace, $string);
50 $string = "$prepend" . "$string" . "$append";
59 // ----------- xl() function wrappers ------------------------------
61 // Use above xl() function the majority of time for translations. The
62 // below wrappers are only for specific situations in order to support
63 // granular control of translations in certain parts of OpenEMR.
69 // xl_document_category()
72 // Added 5-09 by BM for translation of list labels (when applicable)
73 // Only translates if the $GLOBALS['translate_lists'] is set to true.
74 function xl_list_label($constant,$mode='r',$prepend='',$append='') {
75 if ($GLOBALS['translate_lists']) {
78 xl($constant,$mode,$prepend,$append);
81 return xl($constant,$mode,$prepend,$append);
87 echo $prepend.$constant.$append;
90 return $prepend.$constant.$append;
94 // Added 5-09 by BM for translation of layout labels (when applicable)
95 // Only translates if the $GLOBALS['translate_layout'] is set to true.
96 function xl_layout_label($constant,$mode='r',$prepend='',$append='') {
97 if ($GLOBALS['translate_layout']) {
100 xl($constant,$mode,$prepend,$append);
103 return xl($constant,$mode,$prepend,$append);
109 echo $prepend.$constant.$append;
112 return $prepend.$constant.$append;
116 // Added 6-2009 by BM for translation of access control group labels
118 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
119 function xl_gacl_group($constant,$mode='r',$prepend='',$append='') {
120 if ($GLOBALS['translate_gacl_groups']) {
123 xl($constant,$mode,$prepend,$append);
126 return xl($constant,$mode,$prepend,$append);
132 echo $prepend.$constant.$append;
135 return $prepend.$constant.$append;
139 // Added 6-2009 by BM for translation of patient form (notes) titles
141 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
142 function xl_form_title($constant,$mode='r',$prepend='',$append='') {
143 if ($GLOBALS['translate_form_titles']) {
146 xl($constant,$mode,$prepend,$append);
149 return xl($constant,$mode,$prepend,$append);
155 echo $prepend.$constant.$append;
158 return $prepend.$constant.$append;
163 // Added 6-2009 by BM for translation of document categories
165 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
166 function xl_document_category($constant,$mode='r',$prepend='',$append='') {
167 if ($GLOBALS['translate_document_categories']) {
170 xl($constant,$mode,$prepend,$append);
173 return xl($constant,$mode,$prepend,$append);
179 echo $prepend.$constant.$append;
182 return $prepend.$constant.$append;
187 // Added 6-2009 by BM for translation of appointment categories
189 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
190 function xl_appt_category($constant,$mode='r',$prepend='',$append='') {
191 if ($GLOBALS['translate_appt_categories']) {
194 xl($constant,$mode,$prepend,$append);
197 return xl($constant,$mode,$prepend,$append);
203 echo $prepend.$constant.$append;
206 return $prepend.$constant.$append;
210 // ---------------------------------------------------------------------------
212 // ---------------------------------
213 // Miscellaneous language translation functions
215 // Function to return the title of a language from the id
216 // @param integer (language id)
217 // return string (language title)
218 function getLanguageTitle($val) {
220 // validate language id
228 // get language title
229 $res = sqlStatement("select lang_description from lang_languages where lang_id =?",array($lang_id));
230 for ($iter = 0;$row = sqlFetchArray($res);$iter++
) $result[$iter] = $row;
231 $languageTitle = $result[0]{"lang_description"};
232 return $languageTitle;
239 * Returns language directionality as string 'rtl' or 'ltr'
240 * @param int $lang_id language code
241 * @return string 'ltr' 'rtl'
242 * @author Amiel <amielel@matrix.co.il>
244 function getLanguageDir($lang_id) {
245 // validate language id
246 $lang_id = empty($lang_id) ?
1 : $lang_id;
248 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
250 return !empty($row['lang_is_rtl']) ?
'rtl' : 'ltr';
253 //----------------------------------
255 // ----------------------------------------------------------------------------
259 shows some informations for pages html header
264 function html_header_show() {
266 // Below line was commented by the UTF-8 project on 05-2009 by BM.
267 // We commented this out since we are now standardizing encoding
268 // in the globals.php file.
269 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
271 // Keeping this function, since it may prove useful for user interface improvements