Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / library / translation.inc.php
blob3158697db1ddbd55ce771a0445da8ef06743febd
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 if (!empty($GLOBALS['temp_skip_translations'])) {
16 return $constant;
19 // set language id
20 if (!empty($_SESSION['language_choice'])) {
21 $lang_id = $_SESSION['language_choice'];
22 } else {
23 $lang_id = 1;
26 if ($lang_id == 1 && !empty($GLOBALS['skip_english_translation'])) {
27 // language id = 1, so no need to translate
28 // -- remove comments
29 $string = preg_replace('/\{\{.*\}\}/', '', $constant);
30 } else {
31 // TRANSLATE
32 // first, clean lines
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'];
45 if ($string == '') {
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);
54 } else {
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";
63 if ($mode=='e') {
64 echo $string;
65 } else {
66 return $string;
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.
76 // Wrappers:
77 // xl_list_label()
78 // xl_layout_label()
79 // xl_gacl_group()
80 // xl_form_title()
81 // xl_document_category()
82 // xl_appt_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']) {
89 // TRANSLATE
90 if ($mode == "e") {
91 xl($constant, $mode, $prepend, $append);
92 } else {
93 return xl($constant, $mode, $prepend, $append);
95 } else {
96 // DO NOT TRANSLATE
97 if ($mode == "e") {
98 echo $prepend.$constant.$append;
99 } else {
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']) {
109 // TRANSLATE
110 if ($mode == "e") {
111 xl($constant, $mode, $prepend, $append);
112 } else {
113 return xl($constant, $mode, $prepend, $append);
115 } else {
116 // DO NOT TRANSLATE
117 if ($mode == "e") {
118 echo $prepend.$constant.$append;
119 } else {
120 return $prepend.$constant.$append;
124 // Added 6-2009 by BM for translation of access control group labels
125 // (when applicable)
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']) {
130 // TRANSLATE
131 if ($mode == "e") {
132 xl($constant, $mode, $prepend, $append);
133 } else {
134 return xl($constant, $mode, $prepend, $append);
136 } else {
137 // DO NOT TRANSLATE
138 if ($mode == "e") {
139 echo $prepend.$constant.$append;
140 } else {
141 return $prepend.$constant.$append;
145 // Added 6-2009 by BM for translation of patient form (notes) titles
146 // (when applicable)
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']) {
151 // TRANSLATE
152 if ($mode == "e") {
153 xl($constant, $mode, $prepend, $append);
154 } else {
155 return xl($constant, $mode, $prepend, $append);
157 } else {
158 // DO NOT TRANSLATE
159 if ($mode == "e") {
160 echo $prepend.$constant.$append;
161 } else {
162 return $prepend.$constant.$append;
167 // Added 6-2009 by BM for translation of document categories
168 // (when applicable)
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']) {
173 // TRANSLATE
174 if ($mode == "e") {
175 xl($constant, $mode, $prepend, $append);
176 } else {
177 return xl($constant, $mode, $prepend, $append);
179 } else {
180 // DO NOT TRANSLATE
181 if ($mode == "e") {
182 echo $prepend.$constant.$append;
183 } else {
184 return $prepend.$constant.$append;
189 // Added 6-2009 by BM for translation of appointment categories
190 // (when applicable)
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']) {
195 // TRANSLATE
196 if ($mode == "e") {
197 xl($constant, $mode, $prepend, $append);
198 } else {
199 return xl($constant, $mode, $prepend, $append);
201 } else {
202 // DO NOT TRANSLATE
203 if ($mode == "e") {
204 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)
221 // validate language id
222 if (!empty($val)) {
223 $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++) {
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;
250 // get language code
251 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
253 return !empty($row['lang_is_rtl']) ? 'rtl' : 'ltr';