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