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
35 * @link http://galette.tuxfamily.org
36 * @since Available since 0.62
39 if (!defined('GALETTE_ROOT')) {
40 die("Sorry. You can't access directly to this file");
44 use Laminas\Db\Sql\Expression
;
45 use Galette\Core\L10n
;
48 $language = $i18n->getLongID();
51 * Add a translation stored in the database
53 * @param string $text_orig Text to translate
57 function addDynamicTranslation($text_orig)
62 foreach ($i18n->getList() as $lang) {
63 //check if translation already exists
64 $select = $zdb->select(L10n
::TABLE
);
65 $select->columns(array('text_nref'))
68 'text_orig' => $text_orig,
69 'text_locale' => $lang->getLongID()
73 $results = $zdb->execute($select);
74 $result = $results->current();
77 $nref = $result->text_nref
;
80 if (is_numeric($nref) && $nref > 0) {
81 //already existing, update
83 'text_nref' => new Expression('text_nref+1')
86 'Entry for `' . $text_orig .
87 '` dynamic translation already exists.',
91 $owhere = $select->where
;
93 $update = $zdb->update(L10n
::TABLE
);
94 $update->set($values)->where($owhere);
95 $zdb->execute($update);
98 // User is supposed to use current language as original text.
99 $text_trans = $text_orig;
100 if ($lang->getLongID() != $i18n->getLongID()) {
104 'text_orig' => $text_orig,
105 'text_locale' => $lang->getLongID(),
106 'text_trans' => $text_trans
109 $insert = $zdb->insert(L10n
::TABLE
);
110 $insert->values($values);
111 $zdb->execute($insert);
115 } catch (\Exception
$e) {
117 'An error occurred adding dynamic translation for `' .
118 $text_orig . '` | ' . $e->getMessage(),
126 * Delete a translation stored in the database
128 * @param string $text_orig Text to translate
132 function deleteDynamicTranslation($text_orig)
137 $delete = $zdb->delete(L10n
::TABLE
);
140 'text_orig' => $text_orig,
141 'text_locale' => ':lang_id'
144 $stmt = $zdb->sql
->prepareStatementForSqlObject($delete);
146 foreach ($i18n->getList() as $lang) {
149 'where2' => $lang->getLongID()
154 } catch (Exception
$e) {
156 'An error occurred deleting dynamic translation for `' .
157 $text_orig . '` (lang `' . $lang->getLongID() . '`) | ' .
166 * Update a translation stored in the database
168 * @param string $text_orig Text to translate
169 * @param string $text_locale The locale
170 * @param string $text_trans Translated text
174 function updateDynamicTranslation($text_orig, $text_locale, $text_trans)
179 //check if translation already exists
180 $select = $zdb->select(L10n
::TABLE
);
181 $select->columns(array('text_nref'))->where(
183 'text_orig' => $text_orig,
184 'text_locale' => $text_locale
188 $results = $zdb->execute($select);
189 $result = $results->current();
193 $nref = $result->text_nref
;
194 $exists = (is_numeric($nref) && $nref > 0);
198 'text_trans' => $text_trans
202 $owhere = $select->where
;
204 $update = $zdb->update(L10n
::TABLE
);
205 $update->set($values)->where($owhere);
206 $zdb->execute($update);
208 $values['text_orig'] = $text_orig;
209 $values['text_locale'] = $text_locale;
211 $insert = $zdb->insert(L10n
::TABLE
);
212 $insert->values($values);
213 $zdb->execute($insert);
216 } catch (Exception
$e) {
218 'An error occurred updating dynamic translation for `' .
219 $text_orig . '` | ' . $e->getMessage(),
227 * Get a translation stored in the database
229 * @param string $text_orig Text to translate
230 * @param string $text_locale The locale
234 function getDynamicTranslation($text_orig, $text_locale)
238 $select = $zdb->select(L10n
::TABLE
);
239 $select->limit(1)->columns(
243 'text_orig' => $text_orig,
244 'text_locale' => $text_locale
247 $results = $zdb->execute($select);
248 if ($results->count() > 0) {
249 $res = $results->current();
250 return $res->text_trans
;
254 } catch (Exception
$e) {
256 'An error occurred retrieving l10n entry. text_orig=' . $text_orig .
257 ', text_locale=' . $text_locale . ' | ' . $e->getMessage(),
265 * Translate a string, or return original one
267 * @param string $string The string to translate
268 * @param string $domain Translation domain. Default to false (will take default domain)
269 * @param boolean $nt Indicate not translated strings; defaults to true
273 function _T($string, $domain = 'galette', $nt = true)
275 global $language, $installer, $translator;
277 if (strpos($domain, 'route') !== false) {
279 'Routes are no longer translated, return string.',
285 if ($translator->translationExists($string, $domain)) {
286 return $translator->translate($string, $domain);
290 if (!isset($installer) ||
$installer !== true) {
291 $trans = getDynamicTranslation(
300 if (GALETTE_MODE
== 'DEV' && $nt === true) {
301 $trans .= ' (not translated)';
308 * Translate a string, without displaying not translated
310 * @param string $string The string to translate
311 * @param string $domain Translation domain. Default to false (will take default domain)
315 function __($string, $domain = 'galette')
317 return _T($string, $domain, false);
320 /**********************************************
321 * some constant strings found in the database *
322 **********************************************/
323 /** TODO: these string should be not be handled here */
324 $foo = _T("Realization:");
325 $foo = _T("Graphics:");
326 $foo = _T("Publisher:");
327 $foo = _T("President");
328 $foo = _T("Vice-president");
329 $foo = _T("Treasurer");
330 $foo = _T("Vice-treasurer");
331 $foo = _T("Secretary");
332 $foo = _T("Vice-secretary");
333 $foo = _T("Active member");
334 $foo = _T("Benefactor member");
335 $foo = _T("Founder member");
336 $foo = _T("Old-timer");
337 $foo = _T("Legal entity");
338 $foo = _T("Non-member");
339 $foo = _T("Reduced annual contribution");
340 $foo = _T("Company cotisation");
341 $foo = _T("Donation in kind");
342 $foo = _T("Donation in money");
343 $foo = _T("Partnership");
345 $foo = _T("english");
346 $foo = _T("spanish");
347 $foo = _T("annual fee");
348 $foo = _T("annual fee (to be paid)");
349 $foo = _T("company fee");
350 $foo = _T("donation in kind");
351 $foo = _T("donation in money");
352 $foo = _T("partnership");
353 $foo = _T("reduced annual fee");
354 $foo = _T("Identity");
355 $foo = _T("Galette-related data");
356 $foo = _T("Contact information");
360 $foo = _T("Identity:");
361 $foo = _T("Galette-related data:");
362 $foo = _T("Contact information:");
363 $foo = _T("Society");