quick minor path updates (#1968)
[openemr.git] / library / translation.inc.php
blob55b657eb0b8237f38215184145355519471e27d5
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 = '')
15 // set language id
16 if (!empty($_SESSION['language_choice'])) {
17 $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);
26 } else {
27 // TRANSLATE
28 // first, clean lines
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'];
41 if ($string == '') {
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);
50 } else {
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";
59 if ($mode=='e') {
60 echo $string;
61 } else {
62 return $string;
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.
72 // Wrappers:
73 // xl_list_label()
74 // xl_layout_label()
75 // xl_gacl_group()
76 // xl_form_title()
77 // xl_document_category()
78 // xl_appt_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']) {
85 // TRANSLATE
86 if ($mode == "e") {
87 xl($constant, $mode, $prepend, $append);
88 } else {
89 return xl($constant, $mode, $prepend, $append);
91 } else {
92 // DO NOT TRANSLATE
93 if ($mode == "e") {
94 echo $prepend.$constant.$append;
95 } else {
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']) {
105 // TRANSLATE
106 if ($mode == "e") {
107 xl($constant, $mode, $prepend, $append);
108 } else {
109 return xl($constant, $mode, $prepend, $append);
111 } else {
112 // DO NOT TRANSLATE
113 if ($mode == "e") {
114 echo $prepend.$constant.$append;
115 } else {
116 return $prepend.$constant.$append;
120 // Added 6-2009 by BM for translation of access control group labels
121 // (when applicable)
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']) {
126 // TRANSLATE
127 if ($mode == "e") {
128 xl($constant, $mode, $prepend, $append);
129 } else {
130 return xl($constant, $mode, $prepend, $append);
132 } else {
133 // DO NOT TRANSLATE
134 if ($mode == "e") {
135 echo $prepend.$constant.$append;
136 } else {
137 return $prepend.$constant.$append;
141 // Added 6-2009 by BM for translation of patient form (notes) titles
142 // (when applicable)
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']) {
147 // TRANSLATE
148 if ($mode == "e") {
149 xl($constant, $mode, $prepend, $append);
150 } else {
151 return xl($constant, $mode, $prepend, $append);
153 } else {
154 // DO NOT TRANSLATE
155 if ($mode == "e") {
156 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 = '')
168 if ($GLOBALS['translate_document_categories']) {
169 // TRANSLATE
170 if ($mode == "e") {
171 xl($constant, $mode, $prepend, $append);
172 } else {
173 return xl($constant, $mode, $prepend, $append);
175 } else {
176 // DO NOT TRANSLATE
177 if ($mode == "e") {
178 echo $prepend.$constant.$append;
179 } else {
180 return $prepend.$constant.$append;
185 // Added 6-2009 by BM for translation of appointment categories
186 // (when applicable)
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']) {
191 // TRANSLATE
192 if ($mode == "e") {
193 xl($constant, $mode, $prepend, $append);
194 } else {
195 return xl($constant, $mode, $prepend, $append);
197 } else {
198 // DO NOT TRANSLATE
199 if ($mode == "e") {
200 echo $prepend.$constant.$append;
201 } else {
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
218 if (!empty($val)) {
219 $lang_id = $val;
220 } else {
221 $lang_id = 1;
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;
246 // get language code
247 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
249 return !empty($row['lang_is_rtl']) ? 'rtl' : 'ltr';
252 //----------------------------------
254 // ----------------------------------------------------------------------------
256 HEADER HTML
258 shows some informations for pages html header
260 @param none
261 @return void
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