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 if ($GLOBALS['translate_no_safe_apostrophe']) {
46 $patterns = array ('/\n/','/\r/','/\{\{.*\}\}/');
47 $replace = array (' ','','');
48 $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='') {
83 if ($GLOBALS['translate_lists']) {
86 xl($constant,$mode,$prepend,$append);
89 return xl($constant,$mode,$prepend,$append);
95 echo $prepend.$constant.$append;
98 return $prepend.$constant.$append;
102 // Added 5-09 by BM for translation of layout labels (when applicable)
103 // Only translates if the $GLOBALS['translate_layout'] is set to true.
104 function xl_layout_label($constant,$mode='r',$prepend='',$append='') {
105 if ($GLOBALS['translate_layout']) {
108 xl($constant,$mode,$prepend,$append);
111 return xl($constant,$mode,$prepend,$append);
117 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='') {
128 if ($GLOBALS['translate_gacl_groups']) {
131 xl($constant,$mode,$prepend,$append);
134 return xl($constant,$mode,$prepend,$append);
140 echo $prepend.$constant.$append;
143 return $prepend.$constant.$append;
147 // Added 6-2009 by BM for translation of patient form (notes) titles
149 // Only translates if the $GLOBALS['translate_form_titles'] is set to true.
150 function xl_form_title($constant,$mode='r',$prepend='',$append='') {
151 if ($GLOBALS['translate_form_titles']) {
154 xl($constant,$mode,$prepend,$append);
157 return xl($constant,$mode,$prepend,$append);
163 echo $prepend.$constant.$append;
166 return $prepend.$constant.$append;
171 // Added 6-2009 by BM for translation of document categories
173 // Only translates if the $GLOBALS['translate_document_categories'] is set to true.
174 function xl_document_category($constant,$mode='r',$prepend='',$append='') {
175 if ($GLOBALS['translate_document_categories']) {
178 xl($constant,$mode,$prepend,$append);
181 return xl($constant,$mode,$prepend,$append);
187 echo $prepend.$constant.$append;
190 return $prepend.$constant.$append;
195 // Added 6-2009 by BM for translation of appointment categories
197 // Only translates if the $GLOBALS['translate_appt_categories'] is set to true.
198 function xl_appt_category($constant,$mode='r',$prepend='',$append='') {
199 if ($GLOBALS['translate_appt_categories']) {
202 xl($constant,$mode,$prepend,$append);
205 return xl($constant,$mode,$prepend,$append);
211 echo $prepend.$constant.$append;
214 return $prepend.$constant.$append;
218 // ---------------------------------------------------------------------------
220 // ---------------------------------
221 // Miscellaneous language translation functions
223 // Function to return the title of a language from the id
224 // @param integer (language id)
225 // return string (language title)
226 function getLanguageTitle($val) {
228 // validate language id
236 // get language title
237 $res = sqlStatement("select lang_description from lang_languages where lang_id =?",array($lang_id));
238 for ($iter = 0;$row = sqlFetchArray($res);$iter++
) $result[$iter] = $row;
239 $languageTitle = $result[0]{"lang_description"};
240 return $languageTitle;
247 * Returns language directionality as string 'rtl' or 'ltr'
248 * @param int $lang_id language code
249 * @return string 'ltr' 'rtl'
250 * @author Amiel <amielel@matrix.co.il>
252 function getLanguageDir($lang_id) {
253 // validate language id
254 $lang_id = empty($lang_id) ?
1 : $lang_id;
256 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
258 return !empty($row['lang_is_rtl']) ?
'rtl' : 'ltr';
261 //----------------------------------
263 // ----------------------------------------------------------------------------
267 shows some informations for pages html header
272 function html_header_show() {
274 // Below line was commented by the UTF-8 project on 05-2009 by BM.
275 // We commented this out since we are now standardizing encoding
276 // in the globals.php file.
277 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
279 // Keeping this function, since it may prove useful for user interface improvements