3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2003-2014 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 Frédéric Jaqcuot <unknown@unknow.com>
31 * @author Georges Khaznadar (i18n using gettext) <unknown@unknow.com>
32 * @author Johan Cwiklinski <johan@x-tnd.be>
33 * @copyright 2003-2014 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
36 * @link http://galette.tuxfamily.org
37 * @since Available since 0.62
40 if (!defined('GALETTE_ROOT')) {
41 die("Sorry. You can't access directly to this file");
45 use Laminas\Db\Sql\Expression
;
46 use Galette\Core\L10n
;
49 $language = $i18n->getLongID();
52 * Add a translation stored in the database
54 * @param string $text_orig Text to translate
58 function addDynamicTranslation($text_orig)
63 foreach ($i18n->getList() as $lang) {
64 //check if translation already exists
65 $select = $zdb->select(L10n
::TABLE
);
66 $select->columns(array('text_nref'))
69 'text_orig' => $text_orig,
70 'text_locale' => $lang->getLongID()
74 $results = $zdb->execute($select);
75 $result = $results->current();
78 $nref = $result->text_nref
;
81 if (is_numeric($nref) && $nref > 0) {
82 //already existing, update
84 'text_nref' => new Expression('text_nref+1')
87 'Entry for `' . $text_orig .
88 '` dynamic translation already exists.',
92 $owhere = $select->where
;
94 $update = $zdb->update(L10n
::TABLE
);
95 $update->set($values)->where($owhere);
96 $zdb->execute($update);
99 // User is supposed to use current language as original text.
100 $text_trans = $text_orig;
101 if ($lang->getLongID() != $i18n->getLongID()) {
105 'text_orig' => $text_orig,
106 'text_locale' => $lang->getLongID(),
107 'text_trans' => $text_trans
110 $insert = $zdb->insert(L10n
::TABLE
);
111 $insert->values($values);
112 $zdb->execute($insert);
116 } catch (\Exception
$e) {
118 'An error occurred adding dynamic translation for `' .
119 $text_orig . '` | ' . $e->getMessage(),
127 * Delete a translation stored in the database
129 * @param string $text_orig Text to translate
133 function deleteDynamicTranslation($text_orig)
138 $delete = $zdb->delete(L10n
::TABLE
);
141 'text_orig' => $text_orig,
142 'text_locale' => ':lang_id'
145 $stmt = $zdb->sql
->prepareStatementForSqlObject($delete);
147 foreach ($i18n->getList() as $lang) {
150 'where2' => $lang->getLongID()
155 } catch (Exception
$e) {
157 'An error occurred deleting dynamic translation for `' .
158 $text_orig . '` (lang `' . $lang->getLongID() . '`) | ' .
167 * Update a translation stored in the database
169 * @param string $text_orig Text to translate
170 * @param string $text_locale The locale
171 * @param string $text_trans Translated text
175 function updateDynamicTranslation($text_orig, $text_locale, $text_trans)
180 //check if translation already exists
181 $select = $zdb->select(L10n
::TABLE
);
182 $select->columns(array('text_nref'))->where(
184 'text_orig' => $text_orig,
185 'text_locale' => $text_locale
189 $results = $zdb->execute($select);
190 $result = $results->current();
194 $nref = $result->text_nref
;
195 $exists = (is_numeric($nref) && $nref > 0);
199 'text_trans' => $text_trans
203 $owhere = $select->where
;
205 $update = $zdb->update(L10n
::TABLE
);
206 $update->set($values)->where($owhere);
207 $zdb->execute($update);
209 $values['text_orig'] = $text_orig;
210 $values['text_locale'] = $text_locale;
212 $insert = $zdb->insert(L10n
::TABLE
);
213 $insert->values($values);
214 $zdb->execute($insert);
217 } catch (Exception
$e) {
219 'An error occurred updating dynamic translation for `' .
220 $text_orig . '` | ' . $e->getMessage(),
228 * Get a translation stored in the database
230 * @param string $text_orig Text to translate
231 * @param string $text_locale The locale
235 function getDynamicTranslation($text_orig, $text_locale)
239 $select = $zdb->select(L10n
::TABLE
);
240 $select->limit(1)->columns(
244 'text_orig' => $text_orig,
245 'text_locale' => $text_locale
248 $results = $zdb->execute($select);
249 if ($results->count() > 0) {
250 $res = $results->current();
251 return $res->text_trans
;
255 } catch (Exception
$e) {
257 'An error occurred retrieving l10n entry. text_orig=' . $text_orig .
258 ', text_locale=' . $text_locale . ' | ' . $e->getMessage(),
266 * Translate a string, or return original one
268 * @param string $string The string to translate
269 * @param string $domain Translation domain. Default to false (will take default domain)
270 * @param boolean $nt Indicate not translated strings; defaults to true
274 function _T($string, $domain = 'galette', $nt = true)
276 global $language, $installer, $translator;
278 if (strpos($domain, 'route') !== false) {
280 'Routes are no longer translated, return string.',
286 if ($translator->translationExists($string, $domain)) {
287 return $translator->translate($string, $domain);
291 if (!isset($installer) ||
$installer !== true) {
292 $trans = getDynamicTranslation(
301 if (GALETTE_MODE
== 'DEV' && $nt === true) {
302 $trans .= ' (not translated)';
309 * Translate a string, without displaying not translated
311 * @param string $string The string to translate
312 * @param string $domain Translation domain. Default to false (will take default domain)
316 function __($string, $domain = 'galette')
318 return _T($string, $domain, false);
321 /**********************************************
322 * some constant strings found in the database *
323 **********************************************/
324 /** TODO: these string should be not be handled here */
325 $foo = _T("Realization:");
326 $foo = _T("Graphics:");
327 $foo = _T("Publisher:");
328 $foo = _T("President");
329 $foo = _T("Vice-president");
330 $foo = _T("Treasurer");
331 $foo = _T("Vice-treasurer");
332 $foo = _T("Secretary");
333 $foo = _T("Vice-secretary");
334 $foo = _T("Active member");
335 $foo = _T("Benefactor member");
336 $foo = _T("Founder member");
337 $foo = _T("Old-timer");
338 $foo = _T("Legal entity");
339 $foo = _T("Non-member");
340 $foo = _T("Reduced annual contribution");
341 $foo = _T("Company cotisation");
342 $foo = _T("Donation in kind");
343 $foo = _T("Donation in money");
344 $foo = _T("Partnership");
346 $foo = _T("english");
347 $foo = _T("spanish");
348 $foo = _T("annual fee");
349 $foo = _T("annual fee (to be paid)");
350 $foo = _T("company fee");
351 $foo = _T("donation in kind");
352 $foo = _T("donation in money");
353 $foo = _T("partnership");
354 $foo = _T("reduced annual fee");
355 $foo = _T("Identity");
356 $foo = _T("Galette-related data");
357 $foo = _T("Contact information");
361 $foo = _T("Identity:");
362 $foo = _T("Galette-related data:");
363 $foo = _T("Contact information:");
364 $foo = _T("Society");