dolibarr 24.0.0-beta
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';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
38
39// Load translation files required by the page
40$langs->loadLangs(array("companies", "products", "admin", "sms", "other", "errors"));
41
42if (!$user->admin) {
44}
45
46$id = GETPOSTINT('rowid');
47$action = GETPOST('action', 'aZ09');
48$optioncss = GETPOST('optionscss', 'aZ09');
49$contextpage = GETPOST('contextpage', 'aZ09');
50
51$mode = GETPOST('mode', 'aZ09') ? GETPOST('mode', 'aZ09') : 'searchkey';
52
53$langcode = GETPOST('langcode', 'alphanohtml');
54$transkey = GETPOST('transkey', 'alphanohtml');
55if ($mode == 'searchkey') {
56 $transvalue = GETPOST('transvalue', 'alphanohtml');
57} else {
58 $transvalue = GETPOST('transvalue', 'restricthtml');
59}
60
61$entity = $conf->entity;
62if (isModEnabled('multicompany') && !$user->entity) {
63 $entity = GETPOST('entity', 'int');
64}
65
66// Load variable for pagination
67$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
68$sortfield = GETPOST('sortfield', 'aZ09comma');
69$sortorder = GETPOST('sortorder', 'aZ09comma');
70$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
71if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
72 // If $page is not defined, or '' or -1 or if we click on clear filters
73 $page = 0;
74}
75$offset = $limit * $page;
76$pageprev = $page - 1;
77$pagenext = $page + 1;
78if (!$sortfield) {
79 $sortfield = 'lang,transkey';
80}
81if (!$sortorder) {
82 $sortorder = 'ASC,ASC';
83}
84
85// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
86$hookmanager->initHooks(array('admintranslation', 'globaladmin'));
87
88
89/*
90 * Actions
91 */
92$error = 0;
93
94if (GETPOST('cancel', 'alpha')) {
95 $action = 'list';
96 $massaction = '';
97}
98if (!GETPOST('confirmmassaction', 'alpha') && !empty($massaction) && $massaction != 'presend' && $massaction != 'confirm_presend') {
99 $massaction = '';
100}
101
102$parameters = array();
103$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
104if ($reshook < 0) {
105 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
106}
107
108include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
109
110// Purge search criteria
111if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
112 $transkey = '';
113 $transvalue = '';
114 $toselect = array();
115 $search_array_options = array();
116}
117
118if ($action == 'setMAIN_ENABLE_OVERWRITE_TRANSLATION') {
119 if (GETPOST('value')) {
120 dolibarr_set_const($db, 'MAIN_ENABLE_OVERWRITE_TRANSLATION', 1, 'chaine', 0, '', $conf->entity);
121 } else {
122 dolibarr_set_const($db, 'MAIN_ENABLE_OVERWRITE_TRANSLATION', 0, 'chaine', 0, '', $conf->entity);
123 }
124}
125
126if ($action == 'update') {
127 if ($transkey == '') {
128 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("TranslationKey")), null, 'errors');
129 $error++;
130 }
131 if ($transvalue == '') {
132 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewTranslationStringToShow")), null, 'errors');
133 $error++;
134 }
135 if ($entity == '') {
136 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Entity")), null, 'errors');
137 $error++;
138 }
139 if (!$error) {
140 $db->begin();
141
142 $sql = "UPDATE " . MAIN_DB_PREFIX . "overwrite_trans set transkey = '" . $db->escape(
143 $transkey
144 ) . "', transvalue = '" . $db->escape($transvalue) . "', entity = '" . $db->escape(
145 $entity
146 ) . "' WHERE rowid = " . ((int) GETPOST('rowid', 'int'));
147
148 $result = $db->query($sql);
149 if ($result) {
150 $db->commit();
151 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
152 $action = "";
153 $transkey = "";
154 $transvalue = "";
155 } else {
156 $db->rollback();
157 if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
158 setEventMessages($langs->trans("WarningAnEntryAlreadyExistForTransKey"), null, 'warnings');
159 } else {
160 setEventMessages($db->lasterror(), null, 'errors');
161 }
162 $action = '';
163 }
164 }
165}
166
167if ($action == 'add') {
168 $error = 0;
169
170 if (empty($langcode)) {
171 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language")), null, 'errors');
172 $error++;
173 }
174 if ($transkey == '') {
175 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("TranslationKey")), null, 'errors');
176 $error++;
177 }
178 if ($transvalue == '') {
179 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewTranslationStringToShow")), null, 'errors');
180 $error++;
181 }
182 if (!$error) {
183 $db->begin();
184
185 $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).")";
186 $result = $db->query($sql);
187 if ($result) {
188 $db->commit();
189 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
190 $action = "";
191 $transkey = "";
192 $transvalue = "";
193 } else {
194 $db->rollback();
195 if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
196 setEventMessages($langs->trans("WarningAnEntryAlreadyExistForTransKey"), null, 'warnings');
197 } else {
198 setEventMessages($db->lasterror(), null, 'errors');
199 }
200 $action = '';
201 }
202 }
203}
204
205// Delete line from delete picto
206if ($action == 'delete') {
207 $sql = "DELETE FROM ".MAIN_DB_PREFIX."overwrite_trans WHERE rowid = ".((int) $id);
208 $result = $db->query($sql);
209 if ($result) {
210 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
211 } else {
213 }
214}
215
216
217
218
219
220/*
221 * View
222 */
223
224$form = new Form($db);
225$formadmin = new FormAdmin($db);
226
227$wikihelp = 'EN:Setup_Translation|FR:Paramétrage_Traduction|ES:Configuración_Traducción';
228$title = $langs->trans("Translation");
229llxHeader('', $title, $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-translation');
230
231$param = '&mode='.urlencode($mode);
232
233$enabledisablehtml = '<span class="divfilteralone">';
234if (!getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
235 // Button off, click to enable
236 $enabledisablehtml .= '<a class="reposition valignmiddle nounderlineimp" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&token='.newToken().'&value=1'.$param.'">';
237} else {
238 $enabledisablehtml .= '<a class="reposition valignmiddle nounderlineimp" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&token='.newToken().'&value=0'.$param.'">';
239}
240$enabledisablehtml .= $langs->trans("EnableOverwriteTranslation");
241if (!getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
242 // Button off, click to enable
243 $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off', 'class="paddingleft valignmiddle"');
244} else {
245 // Button on, click to disable
246 $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on', 'class="paddingleft valignmiddle"');
247}
248$enabledisablehtml .= '</a>';
249$enabledisablehtml .= '</span>';
250
251$current_language_code = $langs->defaultlang;
252$s = picto_from_langcode($current_language_code);
253$infoOnCurrentLang = $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("CurrentUserLanguage").':</span> <strong>'.$s.' '.$current_language_code.'</strong>', $langs->trans("TranslationDesc")).'</span><br>';
254if (!empty($conf->dol_optimize_smallscreen)) {
255 $infoOnCurrentLang = 1;
256}
257
258print load_fiche_titre($title, $enabledisablehtml, 'language', 0, '', '', $infoOnCurrentLang);
259
260
261if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
262 $param .= '&contextpage='.urlencode($contextpage);
263}
264if ($limit > 0 && $limit != $conf->liste_limit) {
265 $param .= '&limit='.((int) $limit);
266}
267if (isset($optioncss) && $optioncss != '') {
268 $param .= '&optioncss='.urlencode($optioncss);
269}
270if ($langcode) {
271 $param .= '&langcode='.urlencode($langcode);
272}
273if ($transkey) {
274 $param .= '&transkey='.urlencode($transkey);
275}
276if ($transvalue) {
277 $param .= '&transvalue='.urlencode($transvalue);
278}
279
280
281print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
282if ($optioncss != '') {
283 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
284}
285print '<input type="hidden" name="token" value="'.newToken().'">';
286print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
287print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
288print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
289
291
292print dol_get_fiche_head($head, $mode, '', -1, '');
293
294
295$langcode = GETPOSTISSET('langcode') ? GETPOST('langcode') : $langs->defaultlang;
296
297$newlang = new Translate('', $conf);
298$newlang->setDefaultLang($langcode);
299
300$langsenfileonly = new Translate('', $conf);
301$langsenfileonly->setDefaultLang('en_US');
302
303$newlangfileonly = new Translate('', $conf);
304$newlangfileonly->setDefaultLang($langcode);
305
306$recordtoshow = array();
307
308// Search modules dirs
309$modulesdir = dolGetModulesDirs();
310
311$listoffiles = array();
312$listoffilesexternalmodules = array();
313
314// Search into dir of modules (the $modulesdir is already a list that loop on $conf->file->dol_document_root)
315$i = 0;
316foreach ($modulesdir as $keydir => $tmpsearchdir) {
317 $searchdir = $tmpsearchdir; // $searchdir can be '.../htdocs/core/modules/' or '.../htdocs/custom/mymodule/core/modules/'
318
319 // Directory of translation files
320 $dir_lang = dirname(dirname($searchdir))."/langs/".$langcode; // The 2 dirname is to go up in dir for 2 levels
321 $dir_lang_osencoded = dol_osencode($dir_lang);
322
323 $filearray = dol_dir_list($dir_lang_osencoded, 'files', 0, '', '', "name", SORT_ASC, 1);
324
325 foreach ($filearray as $file) {
326 $tmpfile = preg_replace('/.lang/i', '', basename($file['name']));
327 $moduledirname = (basename(dirname(dirname($dir_lang))));
328
329 $langkey = $tmpfile;
330 if ($i > 0) {
331 $langkey .= '@'.$moduledirname;
332 }
333 //var_dump($i.' - '.$keydir.' - '.$dir_lang_osencoded.' -> '.$moduledirname . ' / ' . $tmpfile.' -> '.$langkey);
334
335 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
336 $result = $newlang->load($langkey, 0, 0, '', 0); // Load translation files + database overwrite
337 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
338 $result = $newlangfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
339 if ($result < 0) {
340 print 'Failed to load language file '.$tmpfile.'<br>'."\n";
341 } else {
342 $listoffiles[$langkey] = $tmpfile;
343 if (strpos($langkey, '@') !== false) {
344 $listoffilesexternalmodules[$langkey] = $tmpfile;
345 }
346 }
347 //print 'After loading lang '.$langkey.', newlang has '.count($newlang->tab_translate).' records<br>'."\n";
348
349 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
350 $result = $langsenfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
351 }
352 $i++;
353}
354
355$nbtotaloffiles = count($listoffiles);
356$nbtotaloffilesexternal = count($listoffilesexternalmodules);
357
358if ($mode == 'overwrite') {
359 print '<input type="hidden" name="page" value="'.$page.'">';
360
361 $disabled = '';
362 if ($action == 'edit' || !getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
363 $disabled = ' disabled="disabled"';
364 }
365 $disablededit = '';
366 if ($action == 'edit' || !getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
367 $disablededit = ' disabled';
368 }
369
370 $text = $langs->trans("SomeTranslationAreUncomplete");
371 $urlwikitranslatordoc = 'https://wiki.dolibarr.org/index.php/Translator_documentation';
372 $text .= ' - <a href="'.$urlwikitranslatordoc.'" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeAlso", $langs->transnoentitiesnoconv("Here")).' '.img_picto('', 'url').'</a>.<br>';
373 $infoOnTransProcess = info_admin($text);
374
375 $infoOnTransProcess .= '<div class="justify info">';
376 $infoOnTransProcess .= '<span class="">';
377 $infoOnTransProcess .= $langs->trans("TranslationOverwriteDesc", $langs->transnoentitiesnoconv("Language"), $langs->transnoentitiesnoconv("TranslationKey"), $langs->transnoentitiesnoconv("NewTranslationStringToShow"))."\n";
378 $infoOnTransProcess .= ' ('.$langs->trans("TranslationOverwriteDesc2").').'."<br>\n";
379 $infoOnTransProcess .= '</span></div>';
380
381 // If a cache for translation is on, show a warning.
382 if (isModEnabled('memcached') || getDolGlobalInt('MAIN_USE_CACHE_FOR_TRANSLATION')) {
383 $infoOnTransProcess .= info_admin($langs->trans("CacheForTranslationIsUsed"), 0, 0, '1', 'warning');
384 }
385
386 print $infoOnTransProcess;
387
388 print '<br>';
389
390
391 print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'add').'">';
392 print '<input type="hidden" id="mode" name="mode" value="'.$mode.'">';
393
394 print '<div class="div-table-responsive-no-min">';
395 print '<table class="noborder centpercent">';
396 print '<tr class="liste_titre">';
397 print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
398 print_liste_field_titre("TranslationKey", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
399 print_liste_field_titre("NewTranslationStringToShow", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
400 if (isModEnabled('multicompany') && !$user->entity) {
401 print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'Entity', '', $param, '', $sortfield, $sortorder, 'center ');
402 }
403 print '<td></td>';
404 print "</tr>\n";
405
406
407 // Line to add new record
408 print "\n";
409
410 print '<tr class="oddeven">';
411
412 // Lang
413 print '<td>';
414 print $formadmin->select_language(GETPOST('langcode'), 'langcode', 0, array(), 1, 0, $disablededit ? 1 : 0, 'minwidth100 maxwidth250', 1);
415 print '</td>'."\n";
416
417 // Trans key
418 print '<td>';
419 print '<input type="text" class="flat maxwidthonsmartphone"'.$disablededit.' name="transkey" id="transkey" value="'.(!empty($transkey) ? $transkey : "").'">';
420 print '</td>';
421
422 // Value
423 print '<td>';
424 print '<input type="text" class="quatrevingtpercent"'.$disablededit.' name="transvalue" id="transvalue" value="'.(!empty($transvalue) ? $transvalue : "").'">';
425 print '</td>';
426
427 // Multi company
428 if (isModEnabled('multicompany') && !$user->entity) {
429 print '<td class="center">';
430 print '<input type="text" class="width50 center"' . $disablededit . ' name="entity" id="entity" value="' . (!empty($entity) ? $entity : "") . '">';
431 print '</td>';
432 }
433
434 print '<td class="center">';
435 print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
436 print '<input type="submit" class="button"'.$disabled.' value="'.$langs->trans("Add").'" name="add" title="'.dol_escape_htmltag($langs->trans("YouMustEnableTranslationOverwriteBefore")).'">';
437 print "</td>\n";
438 print '</tr>';
439
440 // Show constants
441 $sql = "SELECT rowid, entity, lang, transkey, transvalue";
442 $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
443 $sql .= " WHERE 1 = 1";
444 $sql .= " AND entity IN (".getEntity('overwrite_trans').")";
445 $sql .= $db->order($sortfield, $sortorder);
446
447 dol_syslog("translation::select from table", LOG_DEBUG);
448 $result = $db->query($sql);
449 if ($result) {
450 $num = $db->num_rows($result);
451 $i = 0;
452
453 while ($i < $num) {
454 $obj = $db->fetch_object($result);
455
456 print "\n";
457
458 print '<tr class="oddeven">';
459
460 // Lang
461 print '<td>'.dol_escape_htmltag($obj->lang).'</td>'."\n";
462
463 // Trans key
464 print '<td>';
465 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
466 print '<input type="text" class="quatrevingtpercent" name="transkey" value="'.dol_escape_htmltag($obj->transkey).'">';
467 } else {
468 print dol_escape_htmltag($obj->transkey);
469 }
470 print '</td>'."\n";
471
472 // Value
473 print '<td class="small">';
474 /*print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
475 print '<input type="hidden" name="const['.$i.'][lang]" value="'.$obj->lang.'">';
476 print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->transkey.'">';
477 print '<input type="text" id="value_'.$i.'" class="flat inputforupdate" size="30" name="const['.$i.'][value]" value="'.dol_escape_htmltag($obj->transvalue).'">';
478 */
479 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
480 print '<input type="text" class="quatrevingtpercent" name="transvalue" value="'.dol_escape_htmltag($obj->transvalue).'">';
481 } else {
482 //print $obj->transkey.' '.$langsenfileonly->tab_translate[$obj->transkey];
483 $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>');
484 /*if ($obj->lang != 'en_US') {
485 $titleforvalue .= '<br>'.$langs->trans("Translation").' '.$obj->lang.' '...;
486 }*/
487 print '<span title="'.dol_escape_htmltag($titleforvalue).'" class="classfortooltip">';
488 print dol_escape_htmltag($obj->transvalue);
489 print '</span>';
490 }
491 print '</td>';
492
493 // Entity limit to superadmin
494 if (isModEnabled('multicompany') && empty($user->entity)) {
495 print '<td class="center">';
496 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
497 print '<input type="text" class="flat" size="1" name="entity" value="' . ((int) $obj->entity) . '">';
498 } else {
499 print dol_escape_htmltag($obj->entity);
500 }
501 print '</td>';
502 } else {
503 print '<input type="hidden" name="const[' . $i . '][entity]" value="' . ((int) $obj->entity) . '">';
504 }
505
506 print '<td class="center">';
507 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
508 print '<input type="hidden" class="button" name="rowid" value="'.$obj->rowid.'">';
509 print '<input type="submit" class="button buttongen button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
510 print ' &nbsp; ';
511 print '<input type="submit" class="button buttongen button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
512 } else {
513 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>';
514 print ' &nbsp; ';
515 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$obj->entity.'&mode='.urlencode($mode).'&action=delete&token='.newToken().'">'.img_delete().'</a>';
516 }
517 print '</td>';
518
519 print "</tr>\n";
520 print "\n";
521 $i++;
522 }
523 }
524
525 print '</table>';
526 print '</div>';
527}
528
529if ($mode == 'searchkey') {
530 $nbempty = 0;
531 //var_dump($langcode);
532 //var_dump($transkey);
533 //var_dump($transvalue);
534 if (empty($langcode) || $langcode == '-1') {
535 $nbempty++;
536 }
537 if (empty($transkey)) {
538 $nbempty++;
539 }
540 if (empty($transvalue)) {
541 $nbempty++;
542 }
543
544 if ($action == 'search' && ($nbempty > 999)) { // 999 to disable this @phpstan-ignore-line
545 setEventMessages($langs->trans("WarningAtLeastKeyOrTranslationRequired"), null, 'warnings');
546 } else {
547 // Now search into translation array
548 foreach ($newlang->tab_translate as $key => $val) {
549 $newtranskey = preg_replace('/\$$/', '', preg_replace('/^\^/', '', $transkey));
550 $newtranskeystart = preg_match('/^\^/', $transkey);
551 $newtranskeyend = preg_match('/\$$/', $transkey);
552 $regexstring = ($newtranskeystart ? '^' : '').preg_quote($newtranskey, '/').($newtranskeyend ? '$' : '');
553 if ($transkey && !preg_match('/'.$regexstring.'/i', $key)) {
554 continue;
555 }
556 if ($transvalue && !preg_match('/'.preg_quote($transvalue, '/').'/i', $val)) {
557 continue;
558 }
559 $recordtoshow[$key] = $val;
560 }
561 }
562
563 //print '<br>';
564 $nbtotalofrecordswithoutfilters = count($newlang->tab_translate);
565 $nbtotalofrecords = count($recordtoshow);
566 $num = $limit + 1;
567 if (($offset + $num) > $nbtotalofrecords) {
568 $num = $limit;
569 }
570
571 //print 'param='.$param.' $_SERVER["PHP_SELF"]='.$_SERVER["PHP_SELF"].' num='.$num.' page='.$page.' nbtotalofrecords='.$nbtotalofrecords." sortfield=".$sortfield." sortorder=".$sortorder;
572 $title = $langs->trans("Translation");
573 if ($nbtotalofrecords > 0) {
574 $title .= ' <span class="opacitymedium colorblack paddingleft small">('.$nbtotalofrecords.' / '.$nbtotalofrecordswithoutfilters.' - <span title="'.dol_escape_htmltag(($nbtotaloffiles - $nbtotaloffilesexternal).' core - '.($nbtotaloffilesexternal).' external').'">'.$nbtotaloffiles.' '.$langs->trans("Files").'</span>)</span>';
575 }
576 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, -1 * $nbtotalofrecords, '', 0, '', '', $limit, 0, 0, 1);
577
578 $massactionbutton = '';
579
580 print '<input type="hidden" id="action" name="action" value="search">';
581 print '<input type="hidden" id="mode" name="mode" value="'.$mode.'">';
582
583 print '<div class="div-table-responsive-no-min">';
584 print '<table class="noborder centpercent">';
585
586 print '<tr class="liste_titre liste_titre_filter">';
587 // Action column
588 if ($conf->main_checkbox_left_column) {
589 print '<td class="center nowraponall">';
590 $searchpicto = $form->showFilterAndCheckAddButtons(!empty($massactionbutton) ? 1 : 0, 'checkforselect', 1);
591 print $searchpicto;
592 print '</td>';
593 }
594 print '<td>';
595 print $formadmin->select_language($langcode, 'langcode', 0, array(), 0, 0, 0, 'minwidth100 maxwidth250', 1);
596 print '</td>'."\n";
597 print '<td>';
598 print '<input type="text" class="flat maxwidthonsmartphone" name="transkey" value="'.dol_escape_htmltag($transkey).'">';
599 print '</td><td>';
600 print '<input type="text" class="quatrevingtpercent" name="transvalue" value="'.dol_escape_htmltag($transvalue).'">';
601 print '<input type="hidden" name="entitysearch" value="'.$conf->entity.'">';
602 print '</td>';
603 print '<td></td>';
604 // Action column
605 if (!$conf->main_checkbox_left_column) {
606 print '<td class="right nowraponall">';
607 $searchpicto = $form->showFilterAndCheckAddButtons(!empty($massactionbutton) ? 1 : 0, 'checkforselect', 1);
608 print $searchpicto;
609 print '</td>';
610 }
611 print '</tr>';
612
613 print '<tr class="liste_titre">';
614 // Action column
615 if ($conf->main_checkbox_left_column) {
617 }
618 print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
619 print_liste_field_titre("TranslationKey", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
620 print_liste_field_titre("CurrentTranslationString", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
622 // Action column
623 if (!$conf->main_checkbox_left_column) {
625 }
626 print "</tr>\n";
627
628
629 if ($sortfield == 'transkey' && strtolower($sortorder) == 'asc') {
630 ksort($recordtoshow);
631 }
632 if ($sortfield == 'transkey' && strtolower($sortorder) == 'desc') {
633 krsort($recordtoshow);
634 }
635 if ($sortfield == 'transvalue' && strtolower($sortorder) == 'asc') {
636 asort($recordtoshow);
637 }
638 if ($sortfield == 'transvalue' && strtolower($sortorder) == 'desc') {
639 arsort($recordtoshow);
640 }
641
642 // Show result
643 $i = 0;
644 foreach ($recordtoshow as $key => $val) {
645 $i++;
646 if ($i <= $offset) {
647 continue;
648 }
649 if ($limit && $i > ($offset + $limit)) {
650 break;
651 }
652
653 print '<tr class="oddeven">';
654 // Action column
655 if ($conf->main_checkbox_left_column) {
656 print '<td class="center nowraponall">';
657 print '</td>';
658 }
659 // Code lang
660 print '<td>'.dolPrintHTML($langcode).'</td>';
661 // Key
662 print '<td class="" title="'.dolPrintHTMLForAttribute($key).'">'.dolPrintHTML($key).'</td>';
663 print '<td class="tdoverflowmax300 small">';
664 $titleforvalue = $langs->trans("Translation").' en_US for key '.$key.':<br>';
665 if (!empty($langsenfileonly->tab_translate[$key])) {
666 if (substr_count($langsenfileonly->tab_translate[$key], '%s') <= 4) { // To avoid errors when more than 4 %s.
667 $titleforvalue .= $langsenfileonly->trans($key);
668 }
669 } else {
670 $titleforvalue .= '<span class="opacitymedium">'.$langs->trans("None").'</span>';
671 }
672 print '<span title="'.dolPrintHTMLForAttribute($titleforvalue).'" class="classfortooltip">';
673 print dolPrintHTML($val);
674 if (substr_count($langsenfileonly->tab_translate[$key] ?? '', '%s') > 5) {
675 print '<br><div class="warning">Error, more than 5 %s in the source</div>';
676 }
677 print '</span>';
678 print '</td>';
679
680 print '<td class="right nowraponall">';
681 if (!empty($newlangfileonly->tab_translate[$key])) {
682 if ($val != $newlangfileonly->tab_translate[$key]) {
683 // retrieve rowid
684 $sql = "SELECT rowid";
685 $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
686 $sql .= " WHERE entity IN (".getEntity('overwrite_trans').")";
687 $sql .= " AND transkey = '".$db->escape($key)."'";
688 dol_syslog("translation::select from table", LOG_DEBUG);
689 $result = $db->query($sql);
690 $obj = null;
691 if ($result) {
692 $obj = $db->fetch_object($result);
693 }
694 if (is_object($obj)) {
695 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>';
696 print ' ';
697 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>';
698 print '&nbsp;&nbsp;';
699 $htmltext = $langs->trans("OriginalValueWas", '<i>'.$newlangfileonly->tab_translate[$key].'</i>');
700 print $form->textwithpicto('', $htmltext, 1, 'info');
701 }
702 } elseif (getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
703 //print $key.'-'.$val;
704 print '<a class="reposition paddingrightonly" href="'.$_SERVER['PHP_SELF'].'?mode=overwrite&langcode='.urlencode($langcode).'&transkey='.urlencode($key).'">'.img_edit_add($langs->trans("TranslationOverwriteKey")).'</a>';
705 }
706
707 if (getDolGlobalInt('MAIN_FEATURES_LEVEL')) {
708 $transifexlangfile = '$'; // $ means 'All'
709 //$transifexurl = 'https://www.transifex.com/dolibarr-association/dolibarr/translate/#'.$langcode.'/'.$transifexlangfile.'?key='.$key;
710 $transifexurl = 'https://app.transifex.com/dolibarr-association/dolibarr/translate/#'.$langcode.'/'.$transifexlangfile.'?q=key%3A'.$key;
711
712 print ' &nbsp; <a href="'.$transifexurl.'" target="transifex">'.img_picto($langs->trans('FixOnTransifex'), 'globe').'</a>';
713 }
714 } else {
715 // retrieve rowid
716 $sql = "SELECT rowid";
717 $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
718 $sql .= " WHERE entity IN (".getEntity('overwrite_trans').")";
719 $sql .= " AND transkey = '".$db->escape($key)."'";
720 dol_syslog("translation::select from table", LOG_DEBUG);
721 $result = $db->query($sql);
722 $obj = null;
723 if ($result) {
724 $obj = $db->fetch_object($result);
725 }
726 if (is_object($obj)) {
727 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>';
728 print ' ';
729 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>';
730 print '&nbsp;&nbsp;';
731
732 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
733 $htmltext = $langs->trans("TransKeyWithoutOriginalValue", $key);
734 print $form->textwithpicto('', $htmltext, 1, 'warning');
735 }
736 }
737 print '</td>';
738
739 // Action column
740 if (!$conf->main_checkbox_left_column) {
741 print'<td></td>';
742 }
743 print '</tr>'."\n";
744 }
745
746 if (empty($recordtoshow)) {
747 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
748 }
749
750 print '</table>';
751 print '</div>';
752}
753
754print dol_get_fiche_end();
755
756print "</form>\n";
757
758if (!empty($langcode)) {
759 dol_set_focus('#transvalue');
760}
761
762// End of page
763llxFooter();
764$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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:64
dolGetModulesDirs($subdir='')
Return list of directories that contain modules.
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)
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
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.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
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.
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)
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
img_edit_add($titlealt='default', $other='')
Show logo "+".
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.