dolibarr 22.0.5
translation.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2017-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
31
40// Load translation files required by the page
41$langs->loadLangs(array("companies", "products", "admin", "sms", "other", "errors"));
42
43if (!$user->admin) {
45}
46
47$id = GETPOSTINT('rowid');
48$action = GETPOST('action', 'aZ09');
49$optioncss = GETPOST('optionscss', 'aZ09');
50$contextpage = GETPOST('contextpage', 'aZ09');
51
52$mode = GETPOST('mode', 'aZ09') ? GETPOST('mode', 'aZ09') : 'searchkey';
53
54$langcode = GETPOST('langcode', 'alphanohtml');
55$transkey = GETPOST('transkey', 'alphanohtml');
56if ($mode == 'searchkey') {
57 $transvalue = GETPOST('transvalue', 'alphanohtml');
58} else {
59 $transvalue = GETPOST('transvalue', 'restricthtml');
60}
61
62$entity = $conf->entity;
63if (isModEnabled('multicompany') && !$user->entity) {
64 $entity = GETPOST('entity', 'int');
65}
66
67// Load variable for pagination
68$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
69$sortfield = GETPOST('sortfield', 'aZ09comma');
70$sortorder = GETPOST('sortorder', 'aZ09comma');
71$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
72if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
73 // If $page is not defined, or '' or -1 or if we click on clear filters
74 $page = 0;
75}
76$offset = $limit * $page;
77$pageprev = $page - 1;
78$pagenext = $page + 1;
79if (!$sortfield) {
80 $sortfield = 'lang,transkey';
81}
82if (!$sortorder) {
83 $sortorder = 'ASC,ASC';
84}
85
86// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
87$hookmanager->initHooks(array('admintranslation', 'globaladmin'));
88
89
90/*
91 * Actions
92 */
93$error = 0;
94
95if (GETPOST('cancel', 'alpha')) {
96 $action = 'list';
97 $massaction = '';
98}
99if (!GETPOST('confirmmassaction', 'alpha') && !empty($massaction) && $massaction != 'presend' && $massaction != 'confirm_presend') {
100 $massaction = '';
101}
102
103$parameters = array();
104$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
105if ($reshook < 0) {
106 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
107}
108
109include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
110
111// Purge search criteria
112if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
113 $transkey = '';
114 $transvalue = '';
115 $toselect = array();
116 $search_array_options = array();
117}
118
119if ($action == 'setMAIN_ENABLE_OVERWRITE_TRANSLATION') {
120 if (GETPOST('value')) {
121 dolibarr_set_const($db, 'MAIN_ENABLE_OVERWRITE_TRANSLATION', 1, 'chaine', 0, '', $conf->entity);
122 } else {
123 dolibarr_set_const($db, 'MAIN_ENABLE_OVERWRITE_TRANSLATION', 0, 'chaine', 0, '', $conf->entity);
124 }
125}
126
127if ($action == 'update') {
128 if ($transkey == '') {
129 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("TranslationKey")), null, 'errors');
130 $error++;
131 }
132 if ($transvalue == '') {
133 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewTranslationStringToShow")), null, 'errors');
134 $error++;
135 }
136 if ($entity == '') {
137 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Entity")), null, 'errors');
138 $error++;
139 }
140 if (!$error) {
141 $db->begin();
142
143 $sql = "UPDATE " . MAIN_DB_PREFIX . "overwrite_trans set transkey = '" . $db->escape(
144 $transkey
145 ) . "', transvalue = '" . $db->escape($transvalue) . "', entity = '" . $db->escape(
146 $entity
147 ) . "' WHERE rowid = " . ((int) GETPOST('rowid', 'int'));
148
149 $result = $db->query($sql);
150 if ($result) {
151 $db->commit();
152 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
153 $action = "";
154 $transkey = "";
155 $transvalue = "";
156 } else {
157 $db->rollback();
158 if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
159 setEventMessages($langs->trans("WarningAnEntryAlreadyExistForTransKey"), null, 'warnings');
160 } else {
161 setEventMessages($db->lasterror(), null, 'errors');
162 }
163 $action = '';
164 }
165 }
166}
167
168if ($action == 'add') {
169 $error = 0;
170
171 if (empty($langcode)) {
172 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language")), null, 'errors');
173 $error++;
174 }
175 if ($transkey == '') {
176 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("TranslationKey")), null, 'errors');
177 $error++;
178 }
179 if ($transvalue == '') {
180 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewTranslationStringToShow")), null, 'errors');
181 $error++;
182 }
183 if (!$error) {
184 $db->begin();
185
186 $sql = "INSERT INTO ".MAIN_DB_PREFIX."overwrite_trans(lang, transkey, transvalue, entity) VALUES ('".$db->escape($langcode)."','".$db->escape($transkey)."','".$db->escape($transvalue)."', ".((int) $conf->entity).")";
187 $result = $db->query($sql);
188 if ($result) {
189 $db->commit();
190 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
191 $action = "";
192 $transkey = "";
193 $transvalue = "";
194 } else {
195 $db->rollback();
196 if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
197 setEventMessages($langs->trans("WarningAnEntryAlreadyExistForTransKey"), null, 'warnings');
198 } else {
199 setEventMessages($db->lasterror(), null, 'errors');
200 }
201 $action = '';
202 }
203 }
204}
205
206// Delete line from delete picto
207if ($action == 'delete') {
208 $sql = "DELETE FROM ".MAIN_DB_PREFIX."overwrite_trans WHERE rowid = ".((int) $id);
209 $result = $db->query($sql);
210 if ($result) {
211 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
212 } else {
213 dol_print_error($db);
214 }
215}
216
217
218
219
220
221/*
222 * View
223 */
224
225$form = new Form($db);
226$formadmin = new FormAdmin($db);
227
228$wikihelp = 'EN:Setup_Translation|FR:Paramétrage_Traduction|ES:Configuración_Traducción';
229llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-translation');
230
231$param = '&mode='.urlencode($mode);
232
233$enabledisablehtml = '';
234$enabledisablehtml .= $langs->trans("EnableOverwriteTranslation").' ';
235if (!getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
236 // Button off, click to enable
237 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&token='.newToken().'&value=1'.$param.'">';
238 $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off');
239 $enabledisablehtml .= '</a>';
240} else {
241 // Button on, click to disable
242 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&token='.newToken().'&value=0'.$param.'">';
243 $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on');
244 $enabledisablehtml .= '</a>';
245}
246
247$current_language_code = $langs->defaultlang;
248$s = picto_from_langcode($current_language_code);
249$infoOnCurrentLang = $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("CurrentUserLanguage").':</span> <strong>'.$s.' '.$current_language_code.'</strong>', $langs->trans("TranslationDesc")).'</span><br>';
250if (!empty($conf->dol_optimize_smallscreen)) {
251 $infoOnCurrentLang = 1;
252}
253
254print load_fiche_titre($langs->trans("Translation"), $enabledisablehtml, 'language', 0, '', '', $infoOnCurrentLang);
255
256
257if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
258 $param .= '&contextpage='.urlencode($contextpage);
259}
260if ($limit > 0 && $limit != $conf->liste_limit) {
261 $param .= '&limit='.((int) $limit);
262}
263if (isset($optioncss) && $optioncss != '') {
264 $param .= '&optioncss='.urlencode($optioncss);
265}
266if ($langcode) {
267 $param .= '&langcode='.urlencode($langcode);
268}
269if ($transkey) {
270 $param .= '&transkey='.urlencode($transkey);
271}
272if ($transvalue) {
273 $param .= '&transvalue='.urlencode($transvalue);
274}
275
276
277print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
278if ($optioncss != '') {
279 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
280}
281print '<input type="hidden" name="token" value="'.newToken().'">';
282print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
283print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
284print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
285
287
288print dol_get_fiche_head($head, $mode, '', -1, '');
289
290
291$langcode = GETPOSTISSET('langcode') ? GETPOST('langcode') : $langs->defaultlang;
292
293$newlang = new Translate('', $conf);
294$newlang->setDefaultLang($langcode);
295
296$langsenfileonly = new Translate('', $conf);
297$langsenfileonly->setDefaultLang('en_US');
298
299$newlangfileonly = new Translate('', $conf);
300$newlangfileonly->setDefaultLang($langcode);
301
302$recordtoshow = array();
303
304// Search modules dirs
305$modulesdir = dolGetModulesDirs();
306
307$listoffiles = array();
308$listoffilesexternalmodules = array();
309
310// Search into dir of modules (the $modulesdir is already a list that loop on $conf->file->dol_document_root)
311$i = 0;
312foreach ($modulesdir as $keydir => $tmpsearchdir) {
313 $searchdir = $tmpsearchdir; // $searchdir can be '.../htdocs/core/modules/' or '.../htdocs/custom/mymodule/core/modules/'
314
315 // Directory of translation files
316 $dir_lang = dirname(dirname($searchdir))."/langs/".$langcode; // The 2 dirname is to go up in dir for 2 levels
317 $dir_lang_osencoded = dol_osencode($dir_lang);
318
319 $filearray = dol_dir_list($dir_lang_osencoded, 'files', 0, '', '', "name", SORT_ASC, 1);
320
321 foreach ($filearray as $file) {
322 $tmpfile = preg_replace('/.lang/i', '', basename($file['name']));
323 $moduledirname = (basename(dirname(dirname($dir_lang))));
324
325 $langkey = $tmpfile;
326 if ($i > 0) {
327 $langkey .= '@'.$moduledirname;
328 }
329 //var_dump($i.' - '.$keydir.' - '.$dir_lang_osencoded.' -> '.$moduledirname . ' / ' . $tmpfile.' -> '.$langkey);
330
331 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
332 $result = $newlang->load($langkey, 0, 0, '', 0); // Load translation files + database overwrite
333 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
334 $result = $newlangfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
335 if ($result < 0) {
336 print 'Failed to load language file '.$tmpfile.'<br>'."\n";
337 } else {
338 $listoffiles[$langkey] = $tmpfile;
339 if (strpos($langkey, '@') !== false) {
340 $listoffilesexternalmodules[$langkey] = $tmpfile;
341 }
342 }
343 //print 'After loading lang '.$langkey.', newlang has '.count($newlang->tab_translate).' records<br>'."\n";
344
345 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
346 $result = $langsenfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
347 }
348 $i++;
349}
350
351$nbtotaloffiles = count($listoffiles);
352$nbtotaloffilesexternal = count($listoffilesexternalmodules);
353
354if ($mode == 'overwrite') {
355 print '<input type="hidden" name="page" value="'.$page.'">';
356
357 $disabled = '';
358 if ($action == 'edit' || !getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
359 $disabled = ' disabled="disabled"';
360 }
361 $disablededit = '';
362 if ($action == 'edit' || !getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
363 $disablededit = ' disabled';
364 }
365
366 $text = $langs->trans("SomeTranslationAreUncomplete");
367 $urlwikitranslatordoc = 'https://wiki.dolibarr.org/index.php/Translator_documentation';
368 $text .= ' - <a href="'.$urlwikitranslatordoc.'" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeAlso", $langs->transnoentitiesnoconv("Here")).' '.img_picto('', 'url').'</a>.<br>';
369 $infoOnTransProcess = info_admin($text);
370
371 $infoOnTransProcess .= '<div class="justify">';
372 $infoOnTransProcess .= '<span class="opacitymedium">';
373 $infoOnTransProcess .= $langs->trans("TranslationOverwriteDesc", $langs->transnoentitiesnoconv("Language"), $langs->transnoentitiesnoconv("TranslationKey"), $langs->transnoentitiesnoconv("NewTranslationStringToShow"))."\n";
374 $infoOnTransProcess .= ' ('.$langs->trans("TranslationOverwriteDesc2").').'."<br>\n";
375 $infoOnTransProcess .= '</span></div>';
376
377 // If a cache for translation is on, show a warning.
378 if (isModEnabled('memcached') || getDolGlobalInt('MAIN_USE_CACHE_FOR_TRANSLATION')) {
379 $infoOnTransProcess .= info_admin($langs->trans("CacheForTranslationIsUsed"), 0, 0, '1', 'warning');
380 }
381
382 print $infoOnTransProcess;
383
384 print '<br>';
385
386
387 print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'add').'">';
388 print '<input type="hidden" id="mode" name="mode" value="'.$mode.'">';
389
390 print '<div class="div-table-responsive-no-min">';
391 print '<table class="noborder centpercent">';
392 print '<tr class="liste_titre">';
393 print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
394 print_liste_field_titre("TranslationKey", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
395 print_liste_field_titre("NewTranslationStringToShow", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
396 if (isModEnabled('multicompany') && !$user->entity) {
397 print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'Entity', '', $param, '', $sortfield, $sortorder, 'center ');
398 }
399 print '<td align="center"></td>';
400 print "</tr>\n";
401
402
403 // Line to add new record
404 print "\n";
405
406 print '<tr class="oddeven">';
407
408 // Lang
409 print '<td>';
410 print $formadmin->select_language(GETPOST('langcode'), 'langcode', 0, array(), 1, 0, $disablededit ? 1 : 0, 'minwidth100 maxwidth250', 1);
411 print '</td>'."\n";
412
413 // Trans key
414 print '<td>';
415 print '<input type="text" class="flat maxwidthonsmartphone"'.$disablededit.' name="transkey" id="transkey" value="'.(!empty($transkey) ? $transkey : "").'">';
416 print '</td>';
417
418 // Value
419 print '<td>';
420 print '<input type="text" class="quatrevingtpercent"'.$disablededit.' name="transvalue" id="transvalue" value="'.(!empty($transvalue) ? $transvalue : "").'">';
421 print '</td>';
422
423 // Multi company
424 if (isModEnabled('multicompany') && !$user->entity) {
425 print '<td class="center">';
426 print '<input type="text" class="width50 center"' . $disablededit . ' name="entity" id="entity" value="' . (!empty($entity) ? $entity : "") . '">';
427 print '</td>';
428 }
429
430 print '<td class="center">';
431 print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
432 print '<input type="submit" class="button"'.$disabled.' value="'.$langs->trans("Add").'" name="add" title="'.dol_escape_htmltag($langs->trans("YouMustEnableTranslationOverwriteBefore")).'">';
433 print "</td>\n";
434 print '</tr>';
435
436 // Show constants
437 $sql = "SELECT rowid, entity, lang, transkey, transvalue";
438 $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
439 $sql .= " WHERE 1 = 1";
440 $sql .= " AND entity IN (".getEntity('overwrite_trans').")";
441 $sql .= $db->order($sortfield, $sortorder);
442
443 dol_syslog("translation::select from table", LOG_DEBUG);
444 $result = $db->query($sql);
445 if ($result) {
446 $num = $db->num_rows($result);
447 $i = 0;
448
449 while ($i < $num) {
450 $obj = $db->fetch_object($result);
451
452 print "\n";
453
454 print '<tr class="oddeven">';
455
456 // Lang
457 print '<td>'.dol_escape_htmltag($obj->lang).'</td>'."\n";
458
459 // Trans key
460 print '<td>';
461 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
462 print '<input type="text" class="quatrevingtpercent" name="transkey" value="'.dol_escape_htmltag($obj->transkey).'">';
463 } else {
464 print dol_escape_htmltag($obj->transkey);
465 }
466 print '</td>'."\n";
467
468 // Value
469 print '<td class="small">';
470 /*print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
471 print '<input type="hidden" name="const['.$i.'][lang]" value="'.$obj->lang.'">';
472 print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->transkey.'">';
473 print '<input type="text" id="value_'.$i.'" class="flat inputforupdate" size="30" name="const['.$i.'][value]" value="'.dol_escape_htmltag($obj->transvalue).'">';
474 */
475 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
476 print '<input type="text" class="quatrevingtpercent" name="transvalue" value="'.dol_escape_htmltag($obj->transvalue).'">';
477 } else {
478 //print $obj->transkey.' '.$langsenfileonly->tab_translate[$obj->transkey];
479 $titleforvalue = $langs->trans("Translation").' en_US for key '.$obj->transkey.':<br>'.(!empty($langsenfileonly->tab_translate[$obj->transkey]) ? $langsenfileonly->trans($obj->transkey) : '<span class="opacitymedium">'.$langs->trans("None").'</span>');
480 /*if ($obj->lang != 'en_US') {
481 $titleforvalue .= '<br>'.$langs->trans("Translation").' '.$obj->lang.' '...;
482 }*/
483 print '<span title="'.dol_escape_htmltag($titleforvalue).'" class="classfortooltip">';
484 print dol_escape_htmltag($obj->transvalue);
485 print '</span>';
486 }
487 print '</td>';
488
489 // Entity limit to superadmin
490 if (isModEnabled('multicompany') && empty($user->entity)) {
491 print '<td class="center">';
492 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
493 print '<input type="text" class="flat" size="1" name="entity" value="' . ((int) $obj->entity) . '">';
494 } else {
495 print dol_escape_htmltag($obj->entity);
496 }
497 print '</td>';
498 } else {
499 print '<input type="hidden" name="const[' . $i . '][entity]" value="' . ((int) $obj->entity) . '">';
500 }
501
502 print '<td class="center">';
503 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
504 print '<input type="hidden" class="button" name="rowid" value="'.$obj->rowid.'">';
505 print '<input type="submit" class="button buttongen button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
506 print ' &nbsp; ';
507 print '<input type="submit" class="button buttongen button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
508 } else {
509 print '<a class="reposition editfielda paddingrightonly" href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$obj->entity.'&mode='.urlencode($mode).'&action=edit&token='.newToken().'">'.img_edit().'</a>';
510 print ' &nbsp; ';
511 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$obj->entity.'&mode='.urlencode($mode).'&action=delete&token='.newToken().'">'.img_delete().'</a>';
512 }
513 print '</td>';
514
515 print "</tr>\n";
516 print "\n";
517 $i++;
518 }
519 }
520
521 print '</table>';
522 print '</div>';
523}
524
525if ($mode == 'searchkey') {
526 $nbempty = 0;
527 //var_dump($langcode);
528 //var_dump($transkey);
529 //var_dump($transvalue);
530 if (empty($langcode) || $langcode == '-1') {
531 $nbempty++;
532 }
533 if (empty($transkey)) {
534 $nbempty++;
535 }
536 if (empty($transvalue)) {
537 $nbempty++;
538 }
539
540 if ($action == 'search' && ($nbempty > 999)) { // 999 to disable this @phpstan-ignore-line
541 setEventMessages($langs->trans("WarningAtLeastKeyOrTranslationRequired"), null, 'warnings');
542 } else {
543 // Now search into translation array
544 foreach ($newlang->tab_translate as $key => $val) {
545 $newtranskey = preg_replace('/\$$/', '', preg_replace('/^\^/', '', $transkey));
546 $newtranskeystart = preg_match('/^\^/', $transkey);
547 $newtranskeyend = preg_match('/\$$/', $transkey);
548 $regexstring = ($newtranskeystart ? '^' : '').preg_quote($newtranskey, '/').($newtranskeyend ? '$' : '');
549 if ($transkey && !preg_match('/'.$regexstring.'/i', $key)) {
550 continue;
551 }
552 if ($transvalue && !preg_match('/'.preg_quote($transvalue, '/').'/i', $val)) {
553 continue;
554 }
555 $recordtoshow[$key] = $val;
556 }
557 }
558
559 //print '<br>';
560 $nbtotalofrecordswithoutfilters = count($newlang->tab_translate);
561 $nbtotalofrecords = count($recordtoshow);
562 $num = $limit + 1;
563 if (($offset + $num) > $nbtotalofrecords) {
564 $num = $limit;
565 }
566
567 //print 'param='.$param.' $_SERVER["PHP_SELF"]='.$_SERVER["PHP_SELF"].' num='.$num.' page='.$page.' nbtotalofrecords='.$nbtotalofrecords." sortfield=".$sortfield." sortorder=".$sortorder;
568 $title = $langs->trans("Translation");
569 if ($nbtotalofrecords > 0) {
570 $title .= ' <span class="opacitymedium colorblack paddingleft">('.$nbtotalofrecords.' / '.$nbtotalofrecordswithoutfilters.' - <span title="'.dol_escape_htmltag(($nbtotaloffiles - $nbtotaloffilesexternal).' core - '.($nbtotaloffilesexternal).' external').'">'.$nbtotaloffiles.' '.$langs->trans("Files").'</span>)</span>';
571 }
572 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, -1 * $nbtotalofrecords, '', 0, '', '', $limit, 0, 0, 1);
573
574 $massactionbutton = '';
575
576 print '<input type="hidden" id="action" name="action" value="search">';
577 print '<input type="hidden" id="mode" name="mode" value="'.$mode.'">';
578
579 print '<div class="div-table-responsive-no-min">';
580 print '<table class="noborder centpercent">';
581
582 print '<tr class="liste_titre liste_titre_filter"><td>';
583 print $formadmin->select_language($langcode, 'langcode', 0, array(), 0, 0, 0, 'minwidth100 maxwidth250', 1);
584 print '</td>'."\n";
585 print '<td>';
586 print '<input type="text" class="flat maxwidthonsmartphone" name="transkey" value="'.dol_escape_htmltag($transkey).'">';
587 print '</td><td>';
588 print '<input type="text" class="quatrevingtpercent" name="transvalue" value="'.dol_escape_htmltag($transvalue).'">';
589 // Limit to superadmin
590 /*if (isModEnabled('multicompany') && !$user->entity)
591 {
592 print '</td><td>';
593 print '<input type="text" class="flat" size="1" name="entitysearch" value="'.$conf->entity.'">';
594 }
595 else
596 {*/
597 print '<input type="hidden" name="entitysearch" value="'.$conf->entity.'">';
598 //}
599 print '</td>';
600 // Action column
601 print '<td class="right nowraponall">';
602 $searchpicto = $form->showFilterAndCheckAddButtons(!empty($massactionbutton) ? 1 : 0, 'checkforselect', 1);
603 print $searchpicto;
604 print '</td>';
605 print '</tr>';
606
607 print '<tr class="liste_titre">';
608 print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
609 print_liste_field_titre("TranslationKey", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
610 print_liste_field_titre("CurrentTranslationString", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
611 //if (isModEnabled('multicompany') && !$user->entity) print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'entity,transkey', '', $param, '', $sortfield, $sortorder);
612 print '<td align="center"></td>';
613 print "</tr>\n";
614
615
616 if ($sortfield == 'transkey' && strtolower($sortorder) == 'asc') {
617 ksort($recordtoshow);
618 }
619 if ($sortfield == 'transkey' && strtolower($sortorder) == 'desc') {
620 krsort($recordtoshow);
621 }
622 if ($sortfield == 'transvalue' && strtolower($sortorder) == 'asc') {
623 asort($recordtoshow);
624 }
625 if ($sortfield == 'transvalue' && strtolower($sortorder) == 'desc') {
626 arsort($recordtoshow);
627 }
628
629 // Show result
630 $i = 0;
631 foreach ($recordtoshow as $key => $val) {
632 $i++;
633 if ($i <= $offset) {
634 continue;
635 }
636 if ($limit && $i > ($offset + $limit)) {
637 break;
638 }
639 print '<tr class="oddeven"><td>'.dolPrintHTML($langcode).'</td>';
640 // Key
641 print '<td class="" title="'.dolPrintHTMLForAttribute($key).'">'.dolPrintHTML($key).'</td>';
642 print '<td class="tdoverflowmax300 small">';
643 $titleforvalue = $langs->trans("Translation").' en_US for key '.$key.':<br>';
644 if (!empty($langsenfileonly->tab_translate[$key])) {
645 if (substr_count($langsenfileonly->tab_translate[$key], '%s') <= 4) { // To avoid errors when more than 4 %s.
646 $titleforvalue .= $langsenfileonly->trans($key);
647 }
648 } else {
649 $titleforvalue .= '<span class="opacitymedium">'.$langs->trans("None").'</span>';
650 }
651 print '<span title="'.dolPrintHTMLForAttribute($titleforvalue).'" class="classfortooltip">';
652 print dolPrintHTML($val);
653 if (substr_count($langsenfileonly->tab_translate[$key] ?? '', '%s') > 5) {
654 print '<br><div class="warning">Error, more than 5 %s in the source</div>';
655 }
656 print '</span>';
657 print '</td>';
658 print '<td class="right nowraponall">';
659 if (!empty($newlangfileonly->tab_translate[$key])) {
660 if ($val != $newlangfileonly->tab_translate[$key]) {
661 // retrieve rowid
662 $sql = "SELECT rowid";
663 $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
664 $sql .= " WHERE entity IN (".getEntity('overwrite_trans').")";
665 $sql .= " AND transkey = '".$db->escape($key)."'";
666 dol_syslog("translation::select from table", LOG_DEBUG);
667 $result = $db->query($sql);
668 $obj = null;
669 if ($result) {
670 $obj = $db->fetch_object($result);
671 }
672 if (is_object($obj)) {
673 print '<a class="editfielda reposition marginrightonly" href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$conf->entity.'&mode=overwrite&action=edit&token='.newToken().'">'.img_edit().'</a>';
674 print ' ';
675 print '<a class="marginleftonly marginrightonly" href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$conf->entity.'&mode='.urlencode($mode).'&action=delete&token='.newToken().'&mode='.urlencode($mode).'">'.img_delete().'</a>';
676 print '&nbsp;&nbsp;';
677 $htmltext = $langs->trans("OriginalValueWas", '<i>'.$newlangfileonly->tab_translate[$key].'</i>');
678 print $form->textwithpicto('', $htmltext, 1, 'info');
679 }
680 } elseif (getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
681 //print $key.'-'.$val;
682 print '<a class="reposition paddingrightonly" href="'.$_SERVER['PHP_SELF'].'?mode=overwrite&langcode='.urlencode($langcode).'&transkey='.urlencode($key).'">'.img_edit_add($langs->trans("TranslationOverwriteKey")).'</a>';
683 }
684
685 if (getDolGlobalInt('MAIN_FEATURES_LEVEL')) {
686 $transifexlangfile = '$'; // $ means 'All'
687 //$transifexurl = 'https://www.transifex.com/dolibarr-association/dolibarr/translate/#'.$langcode.'/'.$transifexlangfile.'?key='.$key;
688 $transifexurl = 'https://app.transifex.com/dolibarr-association/dolibarr/translate/#'.$langcode.'/'.$transifexlangfile.'?q=key%3A'.$key;
689
690 print ' &nbsp; <a href="'.$transifexurl.'" target="transifex">'.img_picto($langs->trans('FixOnTransifex'), 'globe').'</a>';
691 }
692 } else {
693 // retrieve rowid
694 $sql = "SELECT rowid";
695 $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
696 $sql .= " WHERE entity IN (".getEntity('overwrite_trans').")";
697 $sql .= " AND transkey = '".$db->escape($key)."'";
698 dol_syslog("translation::select from table", LOG_DEBUG);
699 $result = $db->query($sql);
700 $obj = null;
701 if ($result) {
702 $obj = $db->fetch_object($result);
703 }
704 if (is_object($obj)) {
705 print '<a class="editfielda reposition marginrightonly" href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$conf->entity.'&mode=overwrite&action=edit&token='.newToken().'">'.img_edit().'</a>';
706 print ' ';
707 print '<a class="marginleftonly marginrightonly" href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$conf->entity.'&mode='.urlencode($mode).'&action=delete&token='.newToken().'&mode='.urlencode($mode).'">'.img_delete().'</a>';
708 print '&nbsp;&nbsp;';
709
710 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
711 $htmltext = $langs->trans("TransKeyWithoutOriginalValue", $key);
712 print $form->textwithpicto('', $htmltext, 1, 'warning');
713 }
714 }
715 /*if (isModEnabled('multicompany') && !$user->entity)
716 {
717 print '<td>'.$val.'</td>';
718 }*/
719 print '</td></tr>'."\n";
720 }
721
722 if (empty($recordtoshow)) {
723 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
724 }
725
726 print '</table>';
727 print '</div>';
728}
729
730print dol_get_fiche_end();
731
732print "</form>\n";
733
734if (!empty($langcode)) {
735 dol_set_focus('#transvalue');
736}
737
738// End of page
739llxFooter();
740$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
translation_prepare_head()
Prepare array with list of tabs.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Class to manage translations.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dolGetModulesDirs($subdir='')
Return list of directories that contain modules.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_edit_add($titlealt='default', $other='')
Show logo +.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.