]>
git.agnieray.net Git - galette.git/blob - galette/includes/smarty_plugins/function._T.php
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Getetxt Smarty plugin for Galette
10 * Copyright © 2008-2020 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
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.
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.
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/>.
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
38 * Smarty translations for Galette
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
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
56 * @return translated string
58 function smarty_function__T($params, &$smarty)
62 if (!isset($domain)) {
66 if (!isset($notrans)) {
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);
76 $ret = _Tn($string, $plural, $count, $domain, $notrans);
79 // a context ha been specified
80 if (isset($context)) {
81 $ret = _Tx($context, $string, $domain, $notrans);
83 //$text = gettext($text);
84 $ret = _T($string, $domain, $notrans);
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);
95 //replace unbreakable spaces
96 $ret = str_replace(' ', ' ', $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');