]> git.agnieray.net Git - galette.git/blob - galette/includes/smarty_plugins/function._T.php
Reword, precision
[galette.git] / galette / includes / smarty_plugins / function._T.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Getetxt Smarty plugin for Galette
7 *
8 * PHP version 5
9 *
10 * Copyright © 2008-2020 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Smarty
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2008-2020 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link http://galette.tuxfamily.org
34 * @since Available since 0.7-dev - 2008-07-17
35 */
36
37 /**
38 * Smarty translations for Galette
39 *
40 * @param array $params An array that can contains:
41 * string: the string to translate
42 * domain: a translation domain name
43 * notrans: do not indicate not translated strings
44 * pattern: A pattern (optional - required if replace present)
45 * replace: Replacement for pattern (optional - required
46 * if pattern present)
47 * escaping: removes non breakable spaces and escape html
48 * - 'html' for HTML escaping
49 * - 'js' for javascript escaping
50 * - 'url' for url escaping
51 * plural: plural form of the string to translate
52 * count: count for plural mode
53 * context: gettext context
54 * @param Smarty $smarty Smarty
55 *
56 * @return translated string
57 */
58 function smarty_function__T($params, &$smarty)
59 {
60 extract($params);
61
62 if (!isset($domain)) {
63 $domain = 'galette';
64 }
65
66 if (!isset($notrans)) {
67 $notrans = true;
68 }
69
70 // use plural if required parameters are set
71 if (isset($count) && isset($plural)) {
72 // a context ha been specified
73 if (isset($context)) {
74 $ret = _Tnx($context, $string, $plural, $count, $domain, $notrans);
75 } else {
76 $ret = _Tn($string, $plural, $count, $domain, $notrans);
77 }
78 } else {
79 // a context ha been specified
80 if (isset($context)) {
81 $ret = _Tx($context, $string, $domain, $notrans);
82 } else {
83 //$text = gettext($text);
84 $ret = _T($string, $domain, $notrans);
85 }
86 }
87
88 //handle replacements. Cannot be done on template side before they're
89 //processed before string has been translated :/
90 if (isset($pattern) && isset($replace)) {
91 $ret = preg_replace($pattern, $replace, $ret);
92 }
93
94 if (isset($escape)) {
95 //replace unbreakable spaces
96 $ret = str_replace('&nbsp;', ' ', $ret);
97 //for the moment, only 'javascript' type is know. 'js' can also be found in legacy code
98 $ret = htmlspecialchars($ret, ENT_QUOTES, 'UTF-8');
99 }
100
101 return $ret;
102 }