fix add_edit_amendments.php
[openemr.git] / library / translation.inc.php
blob5767b2c42753442c6bbd63d21d00cbdafbe2ca46
1 <?php
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
7 // function.
8 //
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='') {
14 // set language id
15 if (!empty($_SESSION['language_choice'])) {
16 $lang_id = $_SESSION['language_choice'];
18 else {
19 $lang_id = 1;
22 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
23 // language id = 1, so no need to translate
24 // -- remove comments
25 $string = preg_replace('/\{\{.*\}\}/', '', $constant);
27 else {
28 // TRANSLATE
29 // first, clean lines
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";
51 if ($mode=='e') {
52 echo $string;
53 } else {
54 return $string;
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.
64 // Wrappers:
65 // xl_list_label()
66 // xl_layout_label()
67 // xl_gacl_group()
68 // xl_form_title()
69 // xl_document_category()
70 // xl_appt_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']) {
76 // TRANSLATE
77 if ($mode == "e") {
78 xl($constant,$mode,$prepend,$append);
80 else {
81 return xl($constant,$mode,$prepend,$append);
84 else {
85 // DO NOT TRANSLATE
86 if ($mode == "e") {
87 echo $prepend.$constant.$append;
89 else {
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']) {
98 // TRANSLATE
99 if ($mode == "e") {
100 xl($constant,$mode,$prepend,$append);
102 else {
103 return xl($constant,$mode,$prepend,$append);
106 else {
107 // DO NOT TRANSLATE
108 if ($mode == "e") {
109 echo $prepend.$constant.$append;
111 else {
112 return $prepend.$constant.$append;
116 // Added 6-2009 by BM for translation of access control group labels
117 // (when applicable)
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']) {
121 // TRANSLATE
122 if ($mode == "e") {
123 xl($constant,$mode,$prepend,$append);
125 else {
126 return xl($constant,$mode,$prepend,$append);
129 else {
130 // DO NOT TRANSLATE
131 if ($mode == "e") {
132 echo $prepend.$constant.$append;
134 else {
135 return $prepend.$constant.$append;
139 // Added 6-2009 by BM for translation of patient form (notes) titles
140 // (when applicable)
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']) {
144 // TRANSLATE
145 if ($mode == "e") {
146 xl($constant,$mode,$prepend,$append);
148 else {
149 return xl($constant,$mode,$prepend,$append);
152 else {
153 // DO NOT TRANSLATE
154 if ($mode == "e") {
155 echo $prepend.$constant.$append;
157 else {
158 return $prepend.$constant.$append;
163 // Added 6-2009 by BM for translation of document categories
164 // (when applicable)
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']) {
168 // TRANSLATE
169 if ($mode == "e") {
170 xl($constant,$mode,$prepend,$append);
172 else {
173 return xl($constant,$mode,$prepend,$append);
176 else {
177 // DO NOT TRANSLATE
178 if ($mode == "e") {
179 echo $prepend.$constant.$append;
181 else {
182 return $prepend.$constant.$append;
187 // Added 6-2009 by BM for translation of appointment categories
188 // (when applicable)
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']) {
192 // TRANSLATE
193 if ($mode == "e") {
194 xl($constant,$mode,$prepend,$append);
196 else {
197 return xl($constant,$mode,$prepend,$append);
200 else {
201 // DO NOT TRANSLATE
202 if ($mode == "e") {
203 echo $prepend.$constant.$append;
205 else {
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
221 if (!empty($val)) {
222 $lang_id = $val;
224 else {
225 $lang_id = 1;
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;
247 // get language code
248 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
250 return !empty($row['lang_is_rtl']) ? 'rtl' : 'ltr';
253 //----------------------------------
255 // ----------------------------------------------------------------------------
257 HEADER HTML
259 shows some informations for pages html header
261 @param none
262 @return void
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