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'];
26 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
27 // language id = 1, so no need to translate
29 $string = preg_replace('/\{\{.*\}\}/', '', $constant);
33 // convert new lines to spaces and remove windows end of lines
34 $patterns = array ('/\n/','/\r/');
35 $replace = array (' ','');
36 $constant = preg_replace($patterns, $replace, $constant);
38 // second, attempt translation
39 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
40 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
41 "lang_id=? AND constant_name = ? LIMIT 1";
42 $res = sqlStatementNoLog($sql, array($lang_id,$constant));
43 $row = SqlFetchArray($res);
44 $string = $row['definition'];
46 $string = "$constant";
49 // remove dangerous characters and remove comments
50 if ($GLOBALS['translate_no_safe_apostrophe']) {
51 $patterns = array ('/\n/','/\r/','/\{\{.*\}\}/');
52 $replace = array (' ','','');
53 $string = preg_replace($patterns, $replace, $string);
55 // convert apostrophes and quotes to safe apostrophe
56 $patterns = array ('/\n/','/\r/','/"/',"/'/",'/\{\{.*\}\}/');
57 $replace = array (' ','','`','`','');
58 $string = preg_replace($patterns, $replace, $string);
62 $string = "$prepend" . "$string" . "$append";
71 // ----------- xl() function wrappers ------------------------------
73 // Use above xl() function the majority of time for translations. The
74 // below wrappers are only for specific situations in order to support
75 // granular control of translations in certain parts of OpenEMR.
81 // xl_document_category()
84 // Added 5-09 by BM for translation of list labels (when applicable)
85 // Only translates if the $GLOBALS['translate_lists'] is set to true.
86 function xl_list_label($constant, $mode = 'r', $prepend = '', $append = '')
88 if ($GLOBALS['translate_lists']) {
91 xl($constant, $mode, $prepend, $append);
93 return xl($constant, $mode, $prepend, $append);
98 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);
113 return xl($constant, $mode, $prepend, $append);
118 echo $prepend.$constant.$append;
120 return $prepend.$constant.$append;
124 // Added 6-2009 by BM for translation of access control group labels
126 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
127 function xl_gacl_group($constant, $mode = 'r', $prepend = '', $append = '')
129 if ($GLOBALS['translate_gacl_groups']) {
132 xl($constant, $mode, $prepend, $append);
134 return xl($constant, $mode, $prepend, $append);
139 echo $prepend.$constant.$append;
141 return $prepend.$constant.$append;
145 // Added 6-2009 by BM for translation of patient form (notes) titles
147 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
148 function xl_form_title($constant, $mode = 'r', $prepend = '', $append = '')
150 if ($GLOBALS['translate_form_titles']) {
153 xl($constant, $mode, $prepend, $append);
155 return xl($constant, $mode, $prepend, $append);
160 echo $prepend.$constant.$append;
162 return $prepend.$constant.$append;
167 // Added 6-2009 by BM for translation of document categories
169 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
170 function xl_document_category($constant, $mode = 'r', $prepend = '', $append = '')
172 if ($GLOBALS['translate_document_categories']) {
175 xl($constant, $mode, $prepend, $append);
177 return xl($constant, $mode, $prepend, $append);
182 echo $prepend.$constant.$append;
184 return $prepend.$constant.$append;
189 // Added 6-2009 by BM for translation of appointment categories
191 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
192 function xl_appt_category($constant, $mode = 'r', $prepend = '', $append = '')
194 if ($GLOBALS['translate_appt_categories']) {
197 xl($constant, $mode, $prepend, $append);
199 return xl($constant, $mode, $prepend, $append);
204 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)
221 // 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++
) {
231 $result[$iter] = $row;
233 $languageTitle = $result[0]{"lang_description"};
234 return $languageTitle;
241 * Returns language directionality as string 'rtl' or 'ltr'
242 * @param int $lang_id language code
243 * @return string 'ltr' 'rtl'
244 * @author Amiel <amielel@matrix.co.il>
246 function getLanguageDir($lang_id)
248 // validate language id
249 $lang_id = empty($lang_id) ?
1 : $lang_id;
251 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
253 return !empty($row['lang_is_rtl']) ?
'rtl' : 'ltr';