minor improvement to tabs style
[openemr.git] / library / translation.inc.php
blob859b4962f64a3131efa2294e41e731e8067b18b0
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 if ($GLOBALS['translate_no_safe_apostrophe']) {
46 $patterns = array ('/\n/','/\r/','/\{\{.*\}\}/');
47 $replace = array (' ','','');
48 $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='') {
83 if ($GLOBALS['translate_lists']) {
84 // TRANSLATE
85 if ($mode == "e") {
86 xl($constant,$mode,$prepend,$append);
88 else {
89 return xl($constant,$mode,$prepend,$append);
92 else {
93 // DO NOT TRANSLATE
94 if ($mode == "e") {
95 echo $prepend.$constant.$append;
97 else {
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']) {
106 // TRANSLATE
107 if ($mode == "e") {
108 xl($constant,$mode,$prepend,$append);
110 else {
111 return xl($constant,$mode,$prepend,$append);
114 else {
115 // DO NOT TRANSLATE
116 if ($mode == "e") {
117 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='') {
128 if ($GLOBALS['translate_gacl_groups']) {
129 // TRANSLATE
130 if ($mode == "e") {
131 xl($constant,$mode,$prepend,$append);
133 else {
134 return xl($constant,$mode,$prepend,$append);
137 else {
138 // DO NOT TRANSLATE
139 if ($mode == "e") {
140 echo $prepend.$constant.$append;
142 else {
143 return $prepend.$constant.$append;
147 // Added 6-2009 by BM for translation of patient form (notes) titles
148 // (when applicable)
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']) {
152 // TRANSLATE
153 if ($mode == "e") {
154 xl($constant,$mode,$prepend,$append);
156 else {
157 return xl($constant,$mode,$prepend,$append);
160 else {
161 // DO NOT TRANSLATE
162 if ($mode == "e") {
163 echo $prepend.$constant.$append;
165 else {
166 return $prepend.$constant.$append;
171 // Added 6-2009 by BM for translation of document categories
172 // (when applicable)
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']) {
176 // TRANSLATE
177 if ($mode == "e") {
178 xl($constant,$mode,$prepend,$append);
180 else {
181 return xl($constant,$mode,$prepend,$append);
184 else {
185 // DO NOT TRANSLATE
186 if ($mode == "e") {
187 echo $prepend.$constant.$append;
189 else {
190 return $prepend.$constant.$append;
195 // Added 6-2009 by BM for translation of appointment categories
196 // (when applicable)
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']) {
200 // TRANSLATE
201 if ($mode == "e") {
202 xl($constant,$mode,$prepend,$append);
204 else {
205 return xl($constant,$mode,$prepend,$append);
208 else {
209 // DO NOT TRANSLATE
210 if ($mode == "e") {
211 echo $prepend.$constant.$append;
213 else {
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
229 if (!empty($val)) {
230 $lang_id = $val;
232 else {
233 $lang_id = 1;
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;
255 // get language code
256 $row = sqlQuery('SELECT * FROM lang_languages WHERE lang_id = ?', array($lang_id));
258 return !empty($row['lang_is_rtl']) ? 'rtl' : 'ltr';
261 //----------------------------------
263 // ----------------------------------------------------------------------------
265 HEADER HTML
267 shows some informations for pages html header
269 @param none
270 @return void
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