dolibarr 25.0.0-alpha
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"));
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 $langs->load('errors');
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 $langs->load('errors');
198 setEventMessages($langs->trans("WarningAnEntryAlreadyExistForTransKey"), null, 'warnings');
199 } else {
200 setEventMessages($db->lasterror(), null, 'errors');
201 }
202 $action = '';
203 }
204 }
205}
206
207// Delete line from delete picto
208if ($action == 'delete') {
209 $sql = "DELETE FROM ".MAIN_DB_PREFIX."overwrite_trans WHERE rowid = ".((int) $id);
210 $result = $db->query($sql);
211 if ($result) {
212 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
213 } else {
214 dol_print_error($db);
215 }
216}
217
218
219
220
221
222/*
223 * View
224 */
225
226$form = new Form($db);
227$formadmin = new FormAdmin($db);
228
229$wikihelp = 'EN:Setup_Translation|FR:Paramétrage_Traduction|ES:Configuración_Traducción';
230$title = $langs->trans("Translation");
231llxHeader('', $title, $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-translation');
232
233$param = '&mode='.urlencode($mode);
234
235$enabledisablehtml = '<span class="divfilteralone">';
236if (!getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
237 // Button off, click to enable
238 $enabledisablehtml .= '<a class="reposition valignmiddle nounderlineimp" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&token='.newToken().'&value=1'.$param.'">';
239} else {
240 $enabledisablehtml .= '<a class="reposition valignmiddle nounderlineimp" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&token='.newToken().'&value=0'.$param.'">';
241}
242$enabledisablehtml .= $langs->trans("EnableOverwriteTranslation");
243if (!getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
244 // Button off, click to enable
245 $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off', 'class="paddingleft valignmiddle"');
246} else {
247 // Button on, click to disable
248 $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on', 'class="paddingleft valignmiddle"');
249}
250$enabledisablehtml .= '</a>';
251$enabledisablehtml .= '</span>';
252
253$current_language_code = $langs->defaultlang;
254$s = picto_from_langcode($current_language_code);
255$infoOnCurrentLang = $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("CurrentUserLanguage").':</span> <strong>'.$s.' '.$current_language_code.'</strong>', $langs->trans("TranslationDesc")).'</span><br>';
256if (!empty($conf->dol_optimize_smallscreen)) {
257 $infoOnCurrentLang = 1;
258}
259
260print load_fiche_titre($title, $enabledisablehtml, 'language', 0, '', '', $infoOnCurrentLang);
261
262
263if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
264 $param .= '&contextpage='.urlencode($contextpage);
265}
266if ($limit > 0 && $limit != $conf->liste_limit) {
267 $param .= '&limit='.((int) $limit);
268}
269if (isset($optioncss) && $optioncss != '') {
270 $param .= '&optioncss='.urlencode($optioncss);
271}
272if ($langcode) {
273 $param .= '&langcode='.urlencode($langcode);
274}
275if ($transkey) {
276 $param .= '&transkey='.urlencode($transkey);
277}
278if ($transvalue) {
279 $param .= '&transvalue='.urlencode($transvalue);
280}
281
282
283print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" spellcheck="false">';
284if ($optioncss != '') {
285 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
286}
287print '<input type="hidden" name="token" value="'.newToken().'">';
288print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
289print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
290print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
291
293
294print dol_get_fiche_head($head, $mode, '', -1, '');
295
296
297$langcode = GETPOSTISSET('langcode') ? GETPOST('langcode') : $langs->defaultlang;
298
299$newlang = new Translate('', $conf);
300$newlang->setDefaultLang($langcode);
301
302$langsenfileonly = new Translate('', $conf);
303$langsenfileonly->setDefaultLang('en_US');
304
305$newlangfileonly = new Translate('', $conf);
306$newlangfileonly->setDefaultLang($langcode);
307
308$recordtoshow = array();
309
310// Search modules dirs
311$modulesdir = dolGetModulesDirs();
312
313$listoffiles = array();
314$listoffilesexternalmodules = array();
315
316// Search into dir of modules (the $modulesdir is already a list that loop on $conf->file->dol_document_root)
317$i = 0;
318foreach ($modulesdir as $keydir => $tmpsearchdir) {
319 $searchdir = $tmpsearchdir; // $searchdir can be '.../htdocs/core/modules/' or '.../htdocs/custom/mymodule/core/modules/'
320
321 // Directory of translation files
322 $dir_lang = dirname(dirname($searchdir))."/langs/".$langcode; // The 2 dirname is to go up in dir for 2 levels
323 $dir_lang_osencoded = dol_osencode($dir_lang);
324
325 $filearray = dol_dir_list($dir_lang_osencoded, 'files', 0, '', '', "name", SORT_ASC, 1);
326
327 foreach ($filearray as $file) {
328 $tmpfile = preg_replace('/.lang/i', '', basename($file['name']));
329 $moduledirname = (basename(dirname(dirname($dir_lang))));
330
331 $langkey = $tmpfile;
332 if ($i > 0) {
333 $langkey .= '@'.$moduledirname;
334 }
335 //var_dump($i.' - '.$keydir.' - '.$dir_lang_osencoded.' -> '.$moduledirname . ' / ' . $tmpfile.' -> '.$langkey);
336
337 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
338 $result = $newlang->load($langkey, 0, 0, '', 0); // Load translation files + database overwrite
339 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
340 $result = $newlangfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
341 if ($result < 0) {
342 print 'Failed to load language file '.$tmpfile.'<br>'."\n";
343 } else {
344 $listoffiles[$langkey] = $tmpfile;
345 if (strpos($langkey, '@') !== false) {
346 $listoffilesexternalmodules[$langkey] = $tmpfile;
347 }
348 }
349 //print 'After loading lang '.$langkey.', newlang has '.count($newlang->tab_translate).' records<br>'."\n";
350
351 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
352 $result = $langsenfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
353 }
354 $i++;
355}
356
357$nbtotaloffiles = count($listoffiles);
358$nbtotaloffilesexternal = count($listoffilesexternalmodules);
359
360if ($mode == 'overwrite') {
361 print '<input type="hidden" name="page" value="'.$page.'">';
362
363 $disabled = '';
364 if ($action == 'edit' || !getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
365 $disabled = ' disabled="disabled"';
366 }
367 $disablededit = '';
368 if ($action == 'edit' || !getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
369 $disablededit = ' disabled';
370 }
371
372 $text = $langs->trans("SomeTranslationAreUncomplete");
373 $urlwikitranslatordoc = 'https://wiki.dolibarr.org/index.php/Translator_documentation';
374 $text .= ' - <a href="'.$urlwikitranslatordoc.'" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeAlso", $langs->transnoentitiesnoconv("Here")).' '.img_picto('', 'url').'</a>.<br>';
375 $infoOnTransProcess = info_admin($text);
376
377 $infoOnTransProcess .= '<div class="justify info">';
378 $infoOnTransProcess .= '<span class="">';
379 $infoOnTransProcess .= $langs->trans("TranslationOverwriteDesc", $langs->transnoentitiesnoconv("Language"), $langs->transnoentitiesnoconv("TranslationKey"), $langs->transnoentitiesnoconv("NewTranslationStringToShow"))."\n";
380 $infoOnTransProcess .= ' ('.$langs->trans("TranslationOverwriteDesc2").').'."<br>\n";
381 $infoOnTransProcess .= '</span></div>';
382
383 // If a cache for translation is on, show a warning.
384 if (isModEnabled('memcached') || getDolGlobalInt('MAIN_USE_CACHE_FOR_TRANSLATION')) {
385 $infoOnTransProcess .= info_admin($langs->trans("CacheForTranslationIsUsed"), 0, 0, '1', 'warning');
386 }
387
388 print $infoOnTransProcess;
389
390 print '<br>';
391
392
393 print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'add').'">';
394 print '<input type="hidden" id="mode" name="mode" value="'.$mode.'">';
395
396 print '<div class="div-table-responsive-no-min">';
397 print '<table class="noborder centpercent">';
398 print '<tr class="liste_titre">';
399 print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
400 print_liste_field_titre("TranslationKey", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
401 print_liste_field_titre("NewTranslationStringToShow", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
402 if (isModEnabled('multicompany') && !$user->entity) {
403 print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'Entity', '', $param, '', $sortfield, $sortorder, 'center ');
404 }
405 print '<td></td>';
406 print "</tr>\n";
407
408
409 // Line to add new record
410 print "\n";
411
412 print '<tr class="oddeven">';
413
414 // Lang
415 print '<td>';
416 print $formadmin->select_language(GETPOST('langcode'), 'langcode', 0, array(), 1, 0, $disablededit ? 1 : 0, 'minwidth100 maxwidth250', 1);
417 print '</td>'."\n";
418
419 // Trans key
420 print '<td>';
421 print '<input type="text" class="flat maxwidthonsmartphone"'.$disablededit.' name="transkey" id="transkey" value="'.(!empty($transkey) ? $transkey : "").'">';
422 print '</td>';
423
424 // Value
425 print '<td>';
426 print '<input type="text" class="quatrevingtpercent"'.$disablededit.' name="transvalue" id="transvalue" value="'.(!empty($transvalue) ? $transvalue : "").'">';
427 print '</td>';
428
429 // Multi company
430 if (isModEnabled('multicompany') && !$user->entity) {
431 print '<td class="center">';
432 print '<input type="text" class="width50 center"' . $disablededit . ' name="entity" id="entity" value="' . (!empty($entity) ? $entity : "") . '">';
433 print '</td>';
434 }
435
436 print '<td class="center">';
437 print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
438 print '<input type="submit" class="button"'.$disabled.' value="'.$langs->trans("Add").'" name="add" title="'.dol_escape_htmltag($langs->trans("YouMustEnableTranslationOverwriteBefore")).'">';
439 print "</td>\n";
440 print '</tr>';
441
442 // Show constants
443 $sql = "SELECT rowid, entity, lang, transkey, transvalue";
444 $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
445 $sql .= " WHERE 1 = 1";
446 $sql .= " AND entity IN (".getEntity('overwrite_trans').")";
447 $sql .= $db->order($sortfield, $sortorder);
448
449 dol_syslog("translation::select from table", LOG_DEBUG);
450 $result = $db->query($sql);
451 if ($result) {
452 $num = $db->num_rows($result);
453 $i = 0;
454
455 while ($i < $num) {
456 $obj = $db->fetch_object($result);
457
458 print "\n";
459
460 print '<tr class="oddeven">';
461
462 // Lang
463 print '<td>'.dol_escape_htmltag($obj->lang).'</td>'."\n";
464
465 // Trans key
466 print '<td>';
467 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
468 print '<input type="text" class="quatrevingtpercent" name="transkey" value="'.dol_escape_htmltag($obj->transkey).'">';
469 } else {
470 print dol_escape_htmltag($obj->transkey);
471 }
472 print '</td>'."\n";
473
474 // Value
475 print '<td class="small">';
476 /*print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
477 print '<input type="hidden" name="const['.$i.'][lang]" value="'.$obj->lang.'">';
478 print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->transkey.'">';
479 print '<input type="text" id="value_'.$i.'" class="flat inputforupdate" size="30" name="const['.$i.'][value]" value="'.dol_escape_htmltag($obj->transvalue).'">';
480 */
481 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
482 print '<input type="text" class="quatrevingtpercent" name="transvalue" value="'.dol_escape_htmltag($obj->transvalue).'">';
483 } else {
484 //print $obj->transkey.' '.$langsenfileonly->tab_translate[$obj->transkey];
485 $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>');
486 /*if ($obj->lang != 'en_US') {
487 $titleforvalue .= '<br>'.$langs->trans("Translation").' '.$obj->lang.' '...;
488 }*/
489 print '<span title="'.dol_escape_htmltag($titleforvalue).'" class="classfortooltip">';
490 print dol_escape_htmltag($obj->transvalue);
491 print '</span>';
492 }
493 print '</td>';
494
495 // Entity limit to superadmin
496 if (isModEnabled('multicompany') && empty($user->entity)) {
497 print '<td class="center">';
498 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
499 print '<input type="text" class="flat" size="1" name="entity" value="' . ((int) $obj->entity) . '">';
500 } else {
501 print dol_escape_htmltag($obj->entity);
502 }
503 print '</td>';
504 } else {
505 print '<input type="hidden" name="const[' . $i . '][entity]" value="' . ((int) $obj->entity) . '">';
506 }
507
508 print '<td class="center">';
509 if ($action == 'edit' && $obj->rowid == GETPOSTINT('rowid')) {
510 print '<input type="hidden" class="button" name="rowid" value="'.$obj->rowid.'">';
511 print '<input type="submit" class="button buttongen button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
512 print ' &nbsp; ';
513 print '<input type="submit" class="button buttongen button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
514 } else {
515 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>';
516 print ' &nbsp; ';
517 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$obj->entity.'&mode='.urlencode($mode).'&action=delete&token='.newToken().'">'.img_delete().'</a>';
518 }
519 print '</td>';
520
521 print "</tr>\n";
522 print "\n";
523 $i++;
524 }
525 }
526
527 print '</table>';
528 print '</div>';
529}
530
531if ($mode == 'searchkey') {
532 $nbempty = 0;
533 //var_dump($langcode);
534 //var_dump($transkey);
535 //var_dump($transvalue);
536 if (empty($langcode) || $langcode == '-1') {
537 $nbempty++;
538 }
539 if (empty($transkey)) {
540 $nbempty++;
541 }
542 if (empty($transvalue)) {
543 $nbempty++;
544 }
545
546 if ($action == 'search' && ($nbempty > 999)) { // 999 to disable this @phpstan-ignore-line
547 setEventMessages($langs->trans("WarningAtLeastKeyOrTranslationRequired"), null, 'warnings');
548 } else {
549 // Now search into translation array
550 foreach ($newlang->tab_translate as $key => $val) {
551 $newtranskey = preg_replace('/\$$/', '', preg_replace('/^\^/', '', $transkey));
552 $newtranskeystart = preg_match('/^\^/', $transkey);
553 $newtranskeyend = preg_match('/\$$/', $transkey);
554 $regexstring = ($newtranskeystart ? '^' : '').preg_quote($newtranskey, '/').($newtranskeyend ? '$' : '');
555 if ($transkey && !preg_match('/'.$regexstring.'/i', $key)) {
556 continue;
557 }
558 if ($transvalue && !preg_match('/'.preg_quote($transvalue, '/').'/i', $val)) {
559 continue;
560 }
561 $recordtoshow[$key] = $val;
562 }
563 }
564
565 //print '<br>';
566 $nbtotalofrecordswithoutfilters = count($newlang->tab_translate);
567 $nbtotalofrecords = count($recordtoshow);
568 $num = $limit + 1;
569 if (($offset + $num) > $nbtotalofrecords) {
570 $num = $limit;
571 }
572
573 //print 'param='.$param.' $_SERVER["PHP_SELF"]='.$_SERVER["PHP_SELF"].' num='.$num.' page='.$page.' nbtotalofrecords='.$nbtotalofrecords." sortfield=".$sortfield." sortorder=".$sortorder;
574 $title = $langs->trans("Translation");
575 if ($nbtotalofrecords > 0) {
576 $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>';
577 }
578 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, -1 * $nbtotalofrecords, '', 0, '', '', $limit, 0, 0, 1);
579
580 $massactionbutton = '';
581
582 print '<input type="hidden" id="action" name="action" value="search">';
583 print '<input type="hidden" id="mode" name="mode" value="'.$mode.'">';
584
585 print '<div class="div-table-responsive-no-min">';
586 print '<table class="noborder centpercent">';
587
588 print '<tr class="liste_titre liste_titre_filter">';
589 // Action column
590 if ($conf->main_checkbox_left_column) {
591 print '<td class="center nowraponall">';
592 $searchpicto = $form->showFilterAndCheckAddButtons(!empty($massactionbutton) ? 1 : 0, 'checkforselect', 1);
593 print $searchpicto;
594 print '</td>';
595 }
596 print '<td>';
597 print $formadmin->select_language($langcode, 'langcode', 0, array(), 0, 0, 0, 'minwidth100 maxwidth250', 1);
598 print '</td>'."\n";
599 print '<td>';
600 print '<input type="text" class="flat maxwidthonsmartphone" name="transkey" value="'.dol_escape_htmltag($transkey).'">';
601 print '</td><td>';
602 print '<input type="text" class="quatrevingtpercent" name="transvalue" value="'.dol_escape_htmltag($transvalue).'">';
603 print '<input type="hidden" name="entitysearch" value="'.$conf->entity.'">';
604 print '</td>';
605 print '<td></td>';
606 // Action column
607 if (!$conf->main_checkbox_left_column) {
608 print '<td class="right nowraponall">';
609 $searchpicto = $form->showFilterAndCheckAddButtons(!empty($massactionbutton) ? 1 : 0, 'checkforselect', 1);
610 print $searchpicto;
611 print '</td>';
612 }
613 print '</tr>';
614
615 print '<tr class="liste_titre">';
616 // Action column
617 if ($conf->main_checkbox_left_column) {
619 }
620 print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
621 print_liste_field_titre("TranslationKey", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
622 print_liste_field_titre("CurrentTranslationString", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
624 // Action column
625 if (!$conf->main_checkbox_left_column) {
627 }
628 print "</tr>\n";
629
630
631 if ($sortfield == 'transkey' && strtolower($sortorder) == 'asc') {
632 ksort($recordtoshow);
633 }
634 if ($sortfield == 'transkey' && strtolower($sortorder) == 'desc') {
635 krsort($recordtoshow);
636 }
637 if ($sortfield == 'transvalue' && strtolower($sortorder) == 'asc') {
638 asort($recordtoshow);
639 }
640 if ($sortfield == 'transvalue' && strtolower($sortorder) == 'desc') {
641 arsort($recordtoshow);
642 }
643
644 // Show result
645 $i = 0;
646 foreach ($recordtoshow as $key => $val) {
647 $i++;
648 if ($i <= $offset) {
649 continue;
650 }
651 if ($limit && $i > ($offset + $limit)) {
652 break;
653 }
654
655 print '<tr class="oddeven">';
656 // Action column
657 if ($conf->main_checkbox_left_column) {
658 print '<td class="center nowraponall">';
659 print '</td>';
660 }
661 // Code lang
662 print '<td>'.dolPrintHTML($langcode).'</td>';
663 // Key
664 print '<td class="" title="'.dolPrintHTMLForAttribute($key).'">'.dolPrintHTML($key).'</td>';
665 print '<td class="tdoverflowmax300 small">';
666 $titleforvalue = $langs->trans("Translation").' en_US for key '.$key.':<br>';
667 if (!empty($langsenfileonly->tab_translate[$key])) {
668 if (substr_count($langsenfileonly->tab_translate[$key], '%s') <= 4) { // To avoid errors when more than 4 %s.
669 $titleforvalue .= $langsenfileonly->trans($key);
670 }
671 } else {
672 $titleforvalue .= '<span class="opacitymedium">'.$langs->trans("None").'</span>';
673 }
674 print '<span title="'.dolPrintHTMLForAttribute($titleforvalue).'" class="classfortooltip">';
675 print dolPrintHTML($val);
676 if (substr_count($langsenfileonly->tab_translate[$key] ?? '', '%s') > 5) {
677 print '<br><div class="warning">Error, more than 5 %s in the source</div>';
678 }
679 print '</span>';
680 print '</td>';
681
682 print '<td class="right nowraponall">';
683 if (!empty($newlangfileonly->tab_translate[$key])) {
684 if ($val != $newlangfileonly->tab_translate[$key]) {
685 // retrieve rowid
686 $sql = "SELECT rowid";
687 $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
688 $sql .= " WHERE entity IN (".getEntity('overwrite_trans').")";
689 $sql .= " AND transkey = '".$db->escape($key)."'";
690 dol_syslog("translation::select from table", LOG_DEBUG);
691 $result = $db->query($sql);
692 $obj = null;
693 if ($result) {
694 $obj = $db->fetch_object($result);
695 }
696 if (is_object($obj)) {
697 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>';
698 print ' ';
699 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>';
700 print '&nbsp;&nbsp;';
701 $htmltext = $langs->trans("OriginalValueWas", '<i>'.$newlangfileonly->tab_translate[$key].'</i>');
702 print $form->textwithpicto('', $htmltext, 1, 'info');
703 }
704 } elseif (getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
705 //print $key.'-'.$val;
706 print '<a class="editfielda reposition paddingrightonly" href="'.$_SERVER['PHP_SELF'].'?mode=overwrite&langcode='.urlencode($langcode).'&transkey='.urlencode($key).'">'.img_edit($langs->trans("TranslationOverwriteKey")).'</a>';
707 }
708
709 if (getDolGlobalInt('MAIN_FEATURES_LEVEL')) {
710 $transifexlangfile = '$'; // $ means 'All'
711 //$transifexurl = 'https://www.transifex.com/dolibarr-association/dolibarr/translate/#'.$langcode.'/'.$transifexlangfile.'?key='.$key;
712 $transifexurl = 'https://app.transifex.com/dolibarr-association/dolibarr/translate/#'.$langcode.'/'.$transifexlangfile.'?q=key%3A'.$key;
713
714 print ' &nbsp; <a href="'.$transifexurl.'" target="transifex">'.img_picto($langs->trans('FixOnTransifex'), 'globe').'</a>';
715 }
716 } else {
717 // retrieve rowid
718 $sql = "SELECT rowid";
719 $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
720 $sql .= " WHERE entity IN (".getEntity('overwrite_trans').")";
721 $sql .= " AND transkey = '".$db->escape($key)."'";
722 dol_syslog("translation::select from table", LOG_DEBUG);
723 $result = $db->query($sql);
724 $obj = null;
725 if ($result) {
726 $obj = $db->fetch_object($result);
727 }
728 if (is_object($obj)) {
729 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>';
730 print ' ';
731 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>';
732 print '&nbsp;&nbsp;';
733
734 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
735 $htmltext = $langs->trans("TransKeyWithoutOriginalValue", $key);
736 print $form->textwithpicto('', $htmltext, 1, 'warning');
737 }
738 }
739 print '</td>';
740
741 // Action column
742 if (!$conf->main_checkbox_left_column) {
743 print'<td></td>';
744 }
745 print '</tr>'."\n";
746 }
747
748 if (empty($recordtoshow)) {
749 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
750 }
751
752 print '</table>';
753 print '</div>';
754}
755
756print dol_get_fiche_end();
757
758print "</form>\n";
759
760if (!empty($langcode)) {
761 dol_set_focus('#transvalue');
762}
763
764// End of page
765llxFooter();
766$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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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:66
dolGetModulesDirs($subdir='')
Return list of directories that contain modules.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.
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.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_set_focus($selector, $nooutput=0)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.