root/trunk/gui/include/i18n.php

Revision 1327, 5.2 kB (checked in by rats, 4 months ago)

* Fixed: --scan-knownbad-files and --check-deleted are no longer supported by rkhunter
* Fixed #1471: chkrootkit should be in lenny / hardy
* Updated Chinese (simplified)
* Updated German
* Fixed #1475: typo on installation (ispcp-setup)
* Fixed: default user for rkhunter.log

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 /**
22  * false: don't set (not even auto),
23  * null: set if missing,
24  * true: force update from session/default, anything else: set it as a language
25  */
26 function curlang($newlang = null, $force = false) {
27     static $language = null;
28
29     // we store old value so if $language is changed old value is returned
30     $_language = $language;
31
32     // forcibly set $language to $newlang (use with CARE!)
33     if ($force) {
34         $language = $newlang;
35         return $_language;
36     }
37
38     if ($language === null || ($newlang !== null && $newlang !== false)) {
39
40         if ($newlang === true || (($newlang === null || $newlang === false) && $language === null)) {
41             $newlang = (isset($_SESSION['user_def_lang'])) ? $_SESSION['user_def_lang'] : Config::get('USER_INITIAL_LANG');
42         }
43
44         if ($newlang !== false) {
45             $language = $newlang;
46         }
47     }
48
49     return ($_language !== null)? $_language : $language;
50
51 }
52
53 /**
54  *     Function:        tr
55  *     Description:    translates a given string into the selected language, if exists
56  *
57  *     @access            public
58  *     @version        2.2
59  *  @author            ispCP Team, Benedikt Heintel (2007), Raphael Geissert (2007)
60  *
61  *     @param        String    $msgid            string to translate
62  *  @param        Mixed    $substitution    prevent the returned string from being replaced with html entities
63  *     @return        String                    translated or original string
64  **/
65 function tr($msgid, $substitution = false) {
66     $sql = Database::getInstance();
67     static $cache = array();
68
69     // detect whether $substitution is really $substitution or just a value to be replaced in $msgstr
70     if (!is_bool($substitution)) {
71         $substitution = false;
72     }
73
74     $lang = curlang();
75     $encoding = 'UTF-8';
76
77     if (isset($cache[$lang][$msgid])) {
78         $msgstr = $cache[$lang][$msgid];
79     } else {
80         $msgstr = $msgid;
81
82         if ($sql) {
83             if (!$substitution) {
84                 // $substitution is true in this call because we need it that way and to prevent an infinite loop
85                 $encoding = tr('encoding', true);
86             }
87             $rs = exec_query($sql, "SELECT `msgstr` FROM " . quoteIdentifier($lang) . " WHERE `msgid` = ?;", array($msgid), false);
88
89             if ($rs && $rs->RowCount() > 0 && $rs->fields['msgstr'] != '') {
90                 $msgstr = $rs->fields['msgstr'];
91             }
92         }
93     }
94
95     if ($msgid == 'encoding' && $msgstr == 'encoding') {
96         $msgstr = $encoding;
97     }
98
99     // Detect comments and strip them if $msgid == $msgstr
100     // e.g.
101     // tr('_: This is just a comment\nReal message to translate here')
102     if ($msgid == $msgstr && substr($msgid, 0, 3) == '_: ' && count($l = explode("\n", $msgid)) > 1) {
103         unset($l[0]);
104         $msgstr = implode("\n", $l);
105     }
106
107     $cache[$lang][$msgid] = $msgstr;
108
109     // Replace values
110     if (func_num_args() > 1) {
111         $argv = func_get_args();
112         unset($argv[0]); //msgid
113
114         if (is_bool($argv[1])) {
115             unset($argv[1]);
116         }
117         $msgstr = vsprintf($msgstr, $argv);
118     }
119
120     if (!$substitution) {
121         $msgstr = replace_html(htmlentities($msgstr, ENT_COMPAT, $encoding));
122     }
123
124     return $msgstr;
125 }
126
127 /**
128  *     Function:        replace_html
129  *     Description:    replaces special encoded strings back to their original signs
130  *
131  *     @access            public
132  *     @version        1.0
133  *  @author            ispCP Team, Benedikt Heintel (2007)
134  *
135  *     @param        $string        string to replace chars
136  *     @return                    string with replaced chars
137  **/
138 function replace_html($string) {
139     $pattern = array (
140                         '#&lt;[ ]*b[ ]*&gt;#i',
141                         '#&lt;[ ]*/[ ]*b[ ]*&gt;#i',
142                         '#&lt;[ ]*em[ ]*&gt;#i',
143                         '#&lt;[ ]*/[ ]*em[ ]*&gt;#i',
144                         '#&lt;[ ]*i[ ]*&gt;#i',
145                         '#&lt;[ ]*/[ ]*i[ ]*&gt;#i',
146                         '#&lt;[ ]*small[ ]*&gt;#i',
147                         '#&lt;[ ]*/[ ]*small[ ]*&gt;#i',
148                         '#&lt;[ ]*br[ ]*(/|)[ ]*&gt;#i'
149                      );
150
151     $replacement = array (
152                             '<b>',
153                             '</b>',
154                             '<em>',
155                             '</em>',
156                             '<i>',
157                             '</i>',
158                             '<small>',
159                             '</small>',
160                             '<br />'
161                          );
162
163     $string = preg_replace($pattern, $replacement, $string);
164
165     return $string;
166 }
167
168 // Dirty hack to make gettext add this entry to the .pot file
169 if (false) {
170     tr('_: Localised language');
171 }
172
173 ?>
Note: See TracBrowser for help on using the browser.