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'];
22 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
23 // language id = 1, so no need to translate
25 $string = preg_replace('/\{\{.*\}\}/', '', $constant);
29 // convert new lines to spaces and remove windows end of lines
30 $patterns = array ('/\n/','/\r/');
31 $replace = array (' ','');
32 $constant = preg_replace($patterns, $replace, $constant);
34 // second, attempt translation
35 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
36 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
37 "lang_id=? AND constant_name = ? LIMIT 1";
38 $res = sqlStatementNoLog($sql, array($lang_id,$constant));
39 $row = SqlFetchArray($res);
40 $string = $row['definition'];
42 $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);
51 // convert apostrophes and quotes to safe apostrophe
52 $patterns = array ('/\n/','/\r/','/"/',"/'/",'/\{\{.*\}\}/');
53 $replace = array (' ','','`','`','');
54 $string = preg_replace($patterns, $replace, $string);
58 $string = "$prepend" . "$string" . "$append";
67 // ----------- xl() function wrappers ------------------------------
69 // Use above xl() function the majority of time for translations. The
70 // below wrappers are only for specific situations in order to support
71 // granular control of translations in certain parts of OpenEMR.
77 // xl_document_category()
80 // Added 5-09 by BM for translation of list labels (when applicable)
81 // Only translates if the $GLOBALS['translate_lists'] is set to true.
82 function xl_list_label($constant, $mode = 'r', $prepend = '', $append = '')
84 if ($GLOBALS['translate_lists']) {
87 xl($constant, $mode, $prepend, $append);
89 return xl($constant, $mode, $prepend, $append);
94 echo $prepend.$constant.$append;
96 return $prepend.$constant.$append;
100 // Added 5-09 by BM for translation of layout labels (when applicable)
101 // Only translates if the $GLOBALS['translate_layout'] is set to true.
102 function xl_layout_label($constant, $mode = 'r', $prepend = '', $append = '')
104 if ($GLOBALS['translate_layout']) {
107 xl($constant, $mode, $prepend, $append);
109 return xl($constant, $mode, $prepend, $append);
114 echo $prepend.$constant.$append;
116 return $prepend.$constant.$append;
120 // Added 6-2009 by BM for translation of access control group labels
122 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
123 function xl_gacl_group($constant, $mode = 'r', $prepend = '', $append = '')
125 if ($GLOBALS['translate_gacl_groups']) {
128 xl($constant, $mode, $prepend, $append);
130 return xl($constant, $mode, $prepend, $append);
135 echo $prepend.$constant.$append;
137 return $prepend.$constant.$append;
141 // Added 6-2009 by BM for translation of patient form (notes) titles
143 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
144 function xl_form_title($constant, $mode = 'r', $prepend = '', $append = '')
146 if ($GLOBALS['translate_form_titles']) {
149 xl($constant, $mode, $prepend, $append);
151 return xl($constant, $mode, $prepend, $append);
156 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 = '')
168 if ($GLOBALS['translate_document_categories']) {
171 xl($constant, $mode, $prepend, $append);
173 return xl($constant, $mode, $prepend, $append);
178 echo $prepend.$constant.$append;
180 return $prepend.$constant.$append;
185 // Added 6-2009 by BM for translation of appointment categories
187 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
188 function xl_appt_category($constant, $mode = 'r', $prepend = '', $append = '')
190 if ($GLOBALS['translate_appt_categories']) {
193 xl($constant, $mode, $prepend, $append);
195 return xl($constant, $mode, $prepend, $append);
200 echo $prepend.$constant.$append;
202 return $prepend.$constant.$append;
206 // ---------------------------------------------------------------------------
208 // ---------------------------------
209 // Miscellaneous language translation functions
211 // Function to return the title of a language from the id
212 // @param integer (language id)
213 // return string (language title)
214 function getLanguageTitle($val)
217 // validate language id
224 // get language title
225 $res = sqlStatement("select lang_description from lang_languages where lang_id =?", array($lang_id));
226 for ($iter = 0; $row = sqlFetchArray($res); $iter++
) {
227 $result[$iter] = $row;
229 $languageTitle = $result[0]{"lang_description"};
230 return $languageTitle;
237 * Returns language directionality as string 'rtl' or 'ltr'
238 * @param int $lang_id language code
239 * @return string 'ltr' 'rtl'
240 * @author Amiel <amielel@matrix.co.il>
242 function getLanguageDir($lang_id)
244 // validate language id
245 $lang_id = empty($lang_id) ?
1 : $lang_id;
247 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
249 return !empty($row['lang_is_rtl']) ?
'rtl' : 'ltr';
252 //----------------------------------
254 // ----------------------------------------------------------------------------
258 shows some informations for pages html header
263 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