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($GLOBALS['temp_skip_translations'])) {
20 if (!empty($_SESSION['language_choice'])) {
21 $lang_id = $_SESSION['language_choice'];
28 // convert new lines to spaces and remove windows end of lines
29 $patterns = array ('/\n/','/\r/');
30 $replace = array (' ','');
31 $constant = preg_replace($patterns, $replace, $constant ??
'');
32 // second, attempt translation
33 $sql = "SELECT * FROM lang_definitions JOIN lang_constants ON " .
34 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
35 "lang_id=? AND constant_name = ? LIMIT 1";
36 $res = sqlStatementNoLog($sql, array($lang_id,$constant));
37 $row = SqlFetchArray($res);
38 $string = $row['definition'] ??
'';
40 $string = "$constant";
42 // remove dangerous characters and remove comments
43 if (!empty($GLOBALS['translate_no_safe_apostrophe'])) {
44 $patterns = array ('/\n/','/\r/','/\{\{.*\}\}/');
45 $replace = array (' ','','');
46 $string = preg_replace($patterns, $replace, $string);
48 // convert apostrophes and quotes to safe apostrophe
49 $patterns = array ('/\n/','/\r/','/"/',"/'/",'/\{\{.*\}\}/');
50 $replace = array (' ','','`','`','');
51 $string = preg_replace($patterns, $replace, $string);
54 $string = "$prepend" . "$string" . "$append";
63 // ----------- xl() function wrappers ------------------------------
65 // Use above xl() function the majority of time for translations. The
66 // below wrappers are only for specific situations in order to support
67 // granular control of translations in certain parts of OpenEMR.
73 // xl_document_category()
76 // Added 5-09 by BM for translation of list labels (when applicable)
77 // Only translates if the $GLOBALS['translate_lists'] is set to true.
78 function xl_list_label($constant, $mode = 'r', $prepend = '', $append = '')
80 if ($GLOBALS['translate_lists']) {
83 xl($constant, $mode, $prepend, $append);
85 return xl($constant, $mode, $prepend, $append);
90 echo $prepend . $constant . $append;
92 return $prepend . $constant . $append;
96 // Added 5-09 by BM for translation of layout labels (when applicable)
97 // Only translates if the $GLOBALS['translate_layout'] is set to true.
98 function xl_layout_label($constant, $mode = 'r', $prepend = '', $append = '')
100 if ($GLOBALS['translate_layout']) {
103 xl($constant, $mode, $prepend, $append);
105 return xl($constant, $mode, $prepend, $append);
110 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 = '')
121 if ($GLOBALS['translate_gacl_groups']) {
124 xl($constant, $mode, $prepend, $append);
126 return xl($constant, $mode, $prepend, $append);
131 echo $prepend . $constant . $append;
133 return $prepend . $constant . $append;
137 // Added 6-2009 by BM for translation of patient form (notes) titles
139 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
140 function xl_form_title($constant, $mode = 'r', $prepend = '', $append = '')
142 if ($GLOBALS['translate_form_titles']) {
145 xl($constant, $mode, $prepend, $append);
147 return xl($constant, $mode, $prepend, $append);
152 echo $prepend . $constant . $append;
154 return $prepend . $constant . $append;
159 // Added 6-2009 by BM for translation of document categories
161 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
162 function xl_document_category($constant, $mode = 'r', $prepend = '', $append = '')
164 if ($GLOBALS['translate_document_categories']) {
167 xl($constant, $mode, $prepend, $append);
169 return xl($constant, $mode, $prepend, $append);
174 echo $prepend . $constant . $append;
176 return $prepend . $constant . $append;
181 // Added 6-2009 by BM for translation of appointment categories
183 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
184 function xl_appt_category($constant, $mode = 'r', $prepend = '', $append = '')
186 if ($GLOBALS['translate_appt_categories']) {
189 xl($constant, $mode, $prepend, $append);
191 return xl($constant, $mode, $prepend, $append);
196 echo $prepend . $constant . $append;
198 return $prepend . $constant . $append;
202 // ---------------------------------------------------------------------------
204 // ---------------------------------
205 // Miscellaneous language translation functions
207 // Function to return the title of a language from the id
208 // @param integer (language id)
209 // return string (language title)
210 function getLanguageTitle($val)
213 // validate language id
220 // get language title
221 $res = sqlStatement("select lang_description from lang_languages where lang_id =?", array($lang_id));
222 for ($iter = 0; $row = sqlFetchArray($res); $iter++
) {
223 $result[$iter] = $row;
225 $languageTitle = $result[0]["lang_description"];
226 return $languageTitle;
233 * Returns language directionality as string 'rtl' or 'ltr'
234 * @param int $lang_id language code
235 * @return string 'ltr' 'rtl'
236 * @author Amiel <amielel@matrix.co.il>
238 function getLanguageDir($lang_id)
240 // validate language id
241 $lang_id = empty($lang_id) ?
1 : $lang_id;
243 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
245 return !empty($row['lang_is_rtl']) ?
'rtl' : 'ltr';