]> git.agnieray.net Git - galette.git/blob - galette/includes/i18n.inc.php
Rely on static methods rather than constants comparison
[galette.git] / galette / includes / i18n.inc.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * i18n functions
7 *
8 * PHP version 5
9 *
10 * Copyright © 2003-2023 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 Main
28 * @package Galette
29 *
30 * @author Frédéric Jacquot <unknown@unknow.com>
31 * @author Georges Khaznadar (i18n using gettext) <unknown@unknow.com>
32 * @author Johan Cwiklinski <johan@x-tnd.be>
33 * @copyright 2003-2023 The Galette Team
34 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
35 * @link http://galette.tuxfamily.org
36 * @since Available since 0.62
37 */
38
39 if (!defined('GALETTE_ROOT')) {
40 die("Sorry. You can't access directly to this file");
41 }
42
43 use Analog\Analog;
44 use Galette\Core\Galette;
45
46 $i18n->updateEnv();
47 global $language;
48 $language = $i18n->getLongID();
49
50 /**
51 * Translate a string, or return original one
52 *
53 * @param string $string The string to translate
54 * @param string $domain Translation domain. Default to galette
55 * @param boolean $nt Indicate not translated strings; defaults to true
56 *
57 * @return string
58 */
59 function _T($string, $domain = 'galette', $nt = true)
60 {
61 global $language, $installer, $translator, $l10n;
62
63 if (empty($string)) {
64 Analog::log(
65 'Cannot translate empty strings..',
66 Analog::INFO
67 );
68 return $string;
69 }
70
71 if (strpos($domain, 'route') !== false) {
72 Analog::log(
73 'Routes are no longer translated, return string.',
74 Analog::DEBUG
75 );
76 return $string;
77 }
78
79 if ($translator->translationExists($string, $domain)) {
80 return $translator->translate($string, $domain);
81 }
82
83 $trans = false;
84 if (!isset($installer) || $installer !== true) {
85 $trans = $l10n->getDynamicTranslation(
86 $string,
87 $language
88 );
89 }
90
91 if (!$trans) {
92 $trans = $string;
93
94 if (Galette::isDebugEnabled() && $nt === true) {
95 $trans .= ' (not translated)';
96 }
97 }
98 return $trans;
99 }
100
101 /**
102 * Pluralized translation
103 *
104 * @param string $singular Singular form of the string to translate
105 * @param string $plural Plural form of the string to translate
106 * @param integer $count Number for count
107 * @param string $domain Translation domain. Default to galette
108 * @param boolean $nt Indicate not translated strings; defaults to true
109 *
110 * @return string
111 */
112 function _Tn($singular, $plural, $count, $domain = 'galette', $nt = true)
113 {
114 global $language, $installer, $translator, $l10n;
115
116 if (empty($singular) || empty($plural)) {
117 Analog::log(
118 'Cannot translate empty strings..',
119 Analog::INFO
120 );
121 return ($count > 1 ? $plural : $singular);
122 }
123
124 if (
125 $translator->translationExists($singular, $domain)
126 && $translator->translationExists($plural, $domain)
127 ) {
128 $ret = $translator->translatePlural(
129 $singular,
130 $plural,
131 $count,
132 $domain
133 );
134 return $ret;
135 }
136
137 if (!isset($installer) || $installer !== true) {
138 $trans = $l10n->getDynamicTranslation(
139 ($count > 1 ? $plural : $singular),
140 $language
141 );
142 }
143
144 if (!$trans) {
145 $trans = ($count > 1 ? $plural : $singular);
146
147 if (Galette::isDebugEnabled() && $nt === true) {
148 $trans .= ' (not translated)';
149 }
150 }
151 return $trans;
152 }
153
154 /**
155 * Contextualized translation
156 *
157 * @param string $context Context
158 * @param string $string The string to translate
159 * @param string $domain Translation domain (defaults to galette)
160 * @param boolean $nt Indicate not translated strings; defaults to true
161 *
162 * @return string
163 */
164 function _Tx($context, $string, $domain = 'galette', $nt = true)
165 {
166 global $language, $installer, $translator, $l10n;
167
168 $cstring = contextualizedString($string, $context);
169 $ret = _T($cstring, $domain);
170 if ($ret == $cstring) {
171 $ret = $string;
172 }
173
174 $trans = false;
175 if (!isset($installer) || $installer !== true) {
176 $trans = $l10n->getDynamicTranslation(
177 $cstring,
178 $language
179 );
180 }
181
182 if (!$trans) {
183 $trans = $ret;
184
185 if (Galette::isDebugEnabled() && $nt === true) {
186 $trans .= ' (not translated)';
187 }
188 }
189 return $trans;
190 }
191
192 /**
193 * Pluralized and contextualized translation
194 *
195 * @param string $context Context
196 * @param string $singular Singular form of the string to translate
197 * @param string $plural Plural form of the string to translate
198 * @param integer $count Number for count
199 * @param string $domain Translation domain. Default to galette
200 * @param boolean $nt Indicate not translated strings; defaults to true
201 *
202 * @return string
203 */
204 function _Tnx($context, $singular, $plural, $count, $domain = 'galette', $nt = true)
205 {
206 global $language, $installer, $translator, $l10n;
207
208 $csingular = contextualizedString($singular, $context);
209 $cplural = contextualizedString($plural, $context);
210 $ret = _Tn(
211 $csingular,
212 $cplural,
213 $count,
214 $domain
215 );
216
217 if ($ret == $csingular) {
218 // No translation
219 $ret = $singular;
220 }
221
222 if ($ret == $cplural) {
223 // No translation
224 $ret = $plural;
225 }
226
227 $trans = false;
228 if (!isset($installer) || $installer !== true) {
229 $trans = $l10n->getDynamicTranslation(
230 ($count > 1 ? $cplural : $csingular),
231 $language
232 );
233 }
234
235 if (!$trans) {
236 $trans = $ret;
237
238 if (Galette::isDebugEnabled() && $nt === true) {
239 $trans .= ' (not translated)';
240 }
241 }
242
243 return $trans;
244 }
245
246 /**
247 * Get contextualized strign (simalates pgettext)
248 *
249 * @param string $string The string to translate
250 * @param string $context The context
251 *
252 * @return string
253 */
254 function contextualizedString($string, $context)
255 {
256 return "{$string}\004{$context}";
257 }
258
259 /**
260 * Translate a string, without displaying not translated
261 *
262 * @param string $string The string to translate
263 * @param string $domain Translation domain. Default to false (will take default domain)
264 *
265 * @return string
266 */
267 function __($string, $domain = 'galette')
268 {
269 return _T($string, $domain, false);
270 }
271
272 /**********************************************
273 * some constant strings found in the database *
274 **********************************************/
275 /** TODO: these string should be not be handled here */
276 $foo = _T("Realization:");
277 $foo = _T("Graphics:");
278 $foo = _T("Publisher:");
279 $foo = _T("President");
280 $foo = _T("Vice-president");
281 $foo = _T("Treasurer");
282 $foo = _T("Vice-treasurer");
283 $foo = _T("Secretary");
284 $foo = _T("Vice-secretary");
285 $foo = _T("Active member");
286 $foo = _T("Benefactor member");
287 $foo = _T("Founder member");
288 $foo = _T("Old-timer");
289 $foo = _T("Legal entity");
290 $foo = _T("Non-member");
291 $foo = _T("Reduced annual contribution");
292 $foo = _T("Company cotisation");
293 $foo = _T("Donation in kind");
294 $foo = _T("Donation in money");
295 $foo = _T("Partnership");
296 $foo = _T("french");
297 $foo = _T("english");
298 $foo = _T("spanish");
299 $foo = _T("annual fee");
300 $foo = _T("annual fee (to be paid)");
301 $foo = _T("company fee");
302 $foo = _T("donation in kind");
303 $foo = _T("donation in money");
304 $foo = _T("partnership");
305 $foo = _T("reduced annual fee");
306 $foo = _T("Identity");
307 $foo = _T("Galette-related data");
308 $foo = _T("Contact information");
309 $foo = _T("Mr.");
310 $foo = _T("Mrs.");
311 $foo = _T("Miss");
312 $foo = _T("Identity:");
313 $foo = _T("Galette-related data:");
314 $foo = _T("Contact information:");
315 $foo = _T("Society");
316 $foo = _T('Politeness');
317 //pdf models
318 $foo = _T('Main');
319 $foo = _T("** Galette identifier, if applicable");
320 $foo = _T("* Only for compagnies");
321 $foo = _T("Hereby, I agree to comply to %s association statutes and its rules.");
322 $foo = _T("At ................................................");
323 $foo = _T("On .......... / .......... / .......... ");
324 $foo = _T("Username");
325 $foo = _T("Email address");
326 $foo = _T("Country");
327 $foo = _T("City");
328 $foo = _T("Zip Code");
329 $foo = _T("First name");
330 $foo = _T("The minimum contribution for each type of membership are defined on the website of the association. The amount of donations are free to be decided by the generous donor.");
331 $foo = _T("Required membership:");
332 $foo = _T("Complete the following form and send it with your funds, in order to complete your subscription.");
333 $foo = _T('on');
334 $foo = _T('from');
335 $foo = _T('to');
336 $foo = _T('Association');