translation.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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 Frédéric France <frederic.france@free.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/translation.php
  21. * \brief Page to show translation information
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("companies", "products", "admin", "sms", "other", "errors"));
  30. if (!$user->admin) {
  31. accessforbidden();
  32. }
  33. $id = GETPOST('rowid', 'int');
  34. $action = GETPOST('action', 'aZ09');
  35. $optioncss = GETPOST('optionscss', 'aZ09');
  36. $contextpage = GETPOST('contextpage', 'aZ09');
  37. $langcode = GETPOST('langcode', 'alphanohtml');
  38. $transkey = GETPOST('transkey', 'alphanohtml');
  39. $transvalue = GETPOST('transvalue', 'restricthtml');
  40. $mode = GETPOST('mode', 'aZ09') ? GETPOST('mode', 'aZ09') : 'searchkey';
  41. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  42. $sortfield = GETPOST('sortfield', 'aZ09comma');
  43. $sortorder = GETPOST('sortorder', 'aZ09comma');
  44. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  45. if (empty($page) || $page == -1) {
  46. $page = 0;
  47. } // If $page is not defined, or '' or -1
  48. $offset = $limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. if (!$sortfield) {
  52. $sortfield = 'lang,transkey';
  53. }
  54. if (!$sortorder) {
  55. $sortorder = 'ASC';
  56. }
  57. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  58. $hookmanager->initHooks(array('admintranslation', 'globaladmin'));
  59. /*
  60. * Actions
  61. */
  62. if (GETPOST('cancel', 'alpha')) {
  63. $action = 'list'; $massaction = '';
  64. }
  65. if (!GETPOST('confirmmassaction', 'alpha') && !empty($massaction) && $massaction != 'presend' && $massaction != 'confirm_presend') {
  66. $massaction = '';
  67. }
  68. $parameters = array();
  69. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  70. if ($reshook < 0) {
  71. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  72. }
  73. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  74. // Purge search criteria
  75. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  76. $transkey = '';
  77. $transvalue = '';
  78. $toselect = array();
  79. $search_array_options = array();
  80. }
  81. if ($action == 'setMAIN_ENABLE_OVERWRITE_TRANSLATION') {
  82. if (GETPOST('value')) {
  83. dolibarr_set_const($db, 'MAIN_ENABLE_OVERWRITE_TRANSLATION', 1, 'chaine', 0, '', $conf->entity);
  84. } else {
  85. dolibarr_set_const($db, 'MAIN_ENABLE_OVERWRITE_TRANSLATION', 0, 'chaine', 0, '', $conf->entity);
  86. }
  87. }
  88. if ($action == 'update') {
  89. if ($transkey == '') {
  90. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Key")), null, 'errors');
  91. $error++;
  92. }
  93. if ($transvalue == '') {
  94. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewTranslationStringToShow")), null, 'errors');
  95. $error++;
  96. }
  97. if (!$error) {
  98. $db->begin();
  99. $sql = "UPDATE ".MAIN_DB_PREFIX."overwrite_trans set transkey = '".$db->escape($transkey)."', transvalue = '".$db->escape($transvalue)."' WHERE rowid = ".((int) GETPOST('rowid', 'int'));
  100. $result = $db->query($sql);
  101. if ($result) {
  102. $db->commit();
  103. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  104. $action = "";
  105. $transkey = "";
  106. $transvalue = "";
  107. } else {
  108. $db->rollback();
  109. if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  110. setEventMessages($langs->trans("WarningAnEntryAlreadyExistForTransKey"), null, 'warnings');
  111. } else {
  112. setEventMessages($db->lasterror(), null, 'errors');
  113. }
  114. $action = '';
  115. }
  116. }
  117. }
  118. if ($action == 'add') {
  119. $error = 0;
  120. if (empty($langcode)) {
  121. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language")), null, 'errors');
  122. $error++;
  123. }
  124. if ($transkey == '') {
  125. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Key")), null, 'errors');
  126. $error++;
  127. }
  128. if ($transvalue == '') {
  129. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewTranslationStringToShow")), null, 'errors');
  130. $error++;
  131. }
  132. if (!$error) {
  133. $db->begin();
  134. $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).")";
  135. $result = $db->query($sql);
  136. if ($result) {
  137. $db->commit();
  138. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  139. $action = "";
  140. $transkey = "";
  141. $transvalue = "";
  142. } else {
  143. $db->rollback();
  144. if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  145. setEventMessages($langs->trans("WarningAnEntryAlreadyExistForTransKey"), null, 'warnings');
  146. } else {
  147. setEventMessages($db->lasterror(), null, 'errors');
  148. }
  149. $action = '';
  150. }
  151. }
  152. }
  153. // Delete line from delete picto
  154. if ($action == 'delete') {
  155. $sql = "DELETE FROM ".MAIN_DB_PREFIX."overwrite_trans WHERE rowid = ".((int) $id);
  156. $result = $db->query($sql);
  157. if ($result) {
  158. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  159. } else {
  160. dol_print_error($db);
  161. }
  162. }
  163. /*
  164. * View
  165. */
  166. $form = new Form($db);
  167. $formadmin = new FormAdmin($db);
  168. $wikihelp = 'EN:Setup_Translation|FR:Paramétrage_Traduction|ES:Configuración_Traducción';
  169. llxHeader('', $langs->trans("Setup"), $wikihelp);
  170. $param = '&mode='.urlencode($mode);
  171. $enabledisablehtml = '';
  172. $enabledisablehtml .= $langs->trans("EnableOverwriteTranslation").' ';
  173. if (!getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
  174. // Button off, click to enable
  175. $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&token='.newToken().'&value=1'.$param.'">';
  176. $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off');
  177. $enabledisablehtml .= '</a>';
  178. } else {
  179. // Button on, click to disable
  180. $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setMAIN_ENABLE_OVERWRITE_TRANSLATION&token='.newToken().'&value=0'.$param.'">';
  181. $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on');
  182. $enabledisablehtml .= '</a>';
  183. }
  184. print load_fiche_titre($langs->trans("Translation"), $enabledisablehtml, 'title_setup');
  185. $current_language_code = $langs->defaultlang;
  186. $s = picto_from_langcode($current_language_code);
  187. print $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("CurrentUserLanguage").':</span> <strong>'.$s.' '.$current_language_code.'</strong>', $langs->trans("TranslationDesc")).'</span><br>';
  188. print '<br>';
  189. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  190. $param .= '&contextpage='.urlencode($contextpage);
  191. }
  192. if ($limit > 0 && $limit != $conf->liste_limit) {
  193. $param .= '&limit='.((int) $limit);
  194. }
  195. if (isset($optioncss) && $optioncss != '') {
  196. $param .= '&optioncss='.urlencode($optioncss);
  197. }
  198. if ($langcode) {
  199. $param .= '&langcode='.urlencode($langcode);
  200. }
  201. if ($transkey) {
  202. $param .= '&transkey='.urlencode($transkey);
  203. }
  204. if ($transvalue) {
  205. $param .= '&transvalue='.urlencode($transvalue);
  206. }
  207. print '<form action="'.$_SERVER["PHP_SELF"].((empty($user->entity) && !empty($debug)) ? '?debug=1' : '').'" method="POST">';
  208. if (isset($optioncss) && $optioncss != '') {
  209. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  210. }
  211. print '<input type="hidden" name="token" value="'.newToken().'">';
  212. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  213. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  214. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  215. $head = translation_prepare_head();
  216. print dol_get_fiche_head($head, $mode, '', -1, '');
  217. $langcode = GETPOSTISSET('langcode') ? GETPOST('langcode') : $langs->defaultlang;
  218. $newlang = new Translate('', $conf);
  219. $newlang->setDefaultLang($langcode);
  220. $langsenfileonly = new Translate('', $conf);
  221. $langsenfileonly->setDefaultLang('en_US');
  222. $newlangfileonly = new Translate('', $conf);
  223. $newlangfileonly->setDefaultLang($langcode);
  224. $recordtoshow = array();
  225. // Search modules dirs
  226. $modulesdir = dolGetModulesDirs();
  227. $listoffiles = array();
  228. $listoffilesexternalmodules = array();
  229. // Search into dir of modules (the $modulesdir is already a list that loop on $conf->file->dol_document_root)
  230. $i = 0;
  231. foreach ($modulesdir as $keydir => $tmpsearchdir) {
  232. $searchdir = $tmpsearchdir; // $searchdir can be '.../htdocs/core/modules/' or '.../htdocs/custom/mymodule/core/modules/'
  233. // Directory of translation files
  234. $dir_lang = dirname(dirname($searchdir))."/langs/".$langcode; // The 2 dirname is to go up in dir for 2 levels
  235. $dir_lang_osencoded = dol_osencode($dir_lang);
  236. $filearray = dol_dir_list($dir_lang_osencoded, 'files', 0, '', '', $sortfield, (strtolower($sortorder) == 'asc' ?SORT_ASC:SORT_DESC), 1);
  237. foreach ($filearray as $file) {
  238. $tmpfile = preg_replace('/.lang/i', '', basename($file['name']));
  239. $moduledirname = (basename(dirname(dirname($dir_lang))));
  240. $langkey = $tmpfile;
  241. if ($i > 0) {
  242. $langkey .= '@'.$moduledirname;
  243. }
  244. //var_dump($i.' - '.$keydir.' - '.$dir_lang_osencoded.' -> '.$moduledirname . ' / ' . $tmpfile.' -> '.$langkey);
  245. $result = $newlang->load($langkey, 0, 0, '', 0); // Load translation files + database overwrite
  246. $result = $newlangfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
  247. if ($result < 0) {
  248. print 'Failed to load language file '.$tmpfile.'<br>'."\n";
  249. } else {
  250. $listoffiles[$langkey] = $tmpfile;
  251. if (strpos($langkey, '@') !== false) {
  252. $listoffilesexternalmodules[$langkey] = $tmpfile;
  253. }
  254. }
  255. //print 'After loading lang '.$langkey.', newlang has '.count($newlang->tab_translate).' records<br>'."\n";
  256. $result = $langsenfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
  257. }
  258. $i++;
  259. }
  260. $nbtotaloffiles = count($listoffiles);
  261. $nbtotaloffilesexternal = count($listoffilesexternalmodules);
  262. if ($mode == 'overwrite') {
  263. print '<input type="hidden" name="page" value="'.$page.'">';
  264. $disabled = '';
  265. if ($action == 'edit' || !getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
  266. $disabled = ' disabled="disabled"';
  267. }
  268. $disablededit = '';
  269. if ($action == 'edit' || !getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
  270. $disablededit = ' disabled';
  271. }
  272. print '<div class="justify"><span class="opacitymedium">';
  273. print img_info().' '.$langs->trans("SomeTranslationAreUncomplete");
  274. $urlwikitranslatordoc = 'https://wiki.dolibarr.org/index.php/Translator_documentation';
  275. print ' ('.str_replace('{s1}', '<a href="'.$urlwikitranslatordoc.'" target="_blank" rel="noopener noreferrer external">'.$langs->trans("Here").'</a>', $langs->trans("SeeAlso", '{s1}')).')<br>';
  276. print $langs->trans("TranslationOverwriteDesc", $langs->transnoentitiesnoconv("Language"), $langs->transnoentitiesnoconv("Key"), $langs->transnoentitiesnoconv("NewTranslationStringToShow"))."\n";
  277. print ' ('.$langs->trans("TranslationOverwriteDesc2").').'."<br>\n";
  278. print '</span></div>';
  279. print '<br>';
  280. print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'add').'">';
  281. print '<input type="hidden" id="mode" name="mode" value="'.$mode.'">';
  282. print '<div class="div-table-responsive-no-min">';
  283. print '<table class="noborder centpercent">';
  284. print '<tr class="liste_titre">';
  285. print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
  286. print_liste_field_titre("Key", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
  287. print_liste_field_titre("NewTranslationStringToShow", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
  288. //if (isModEnabled('multicompany') && !$user->entity) print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'entity,transkey', '', $param, '', $sortfield, $sortorder);
  289. print '<td align="center"></td>';
  290. print "</tr>\n";
  291. // Line to add new record
  292. print "\n";
  293. print '<tr class="oddeven"><td>';
  294. print $formadmin->select_language(GETPOST('langcode'), 'langcode', 0, null, 1, 0, $disablededit ? 1 : 0, 'maxwidth250', 1);
  295. print '</td>'."\n";
  296. print '<td>';
  297. print '<input type="text" class="flat maxwidthonsmartphone"'.$disablededit.' name="transkey" id="transkey" value="'.(!empty($transkey) ? $transkey : "").'">';
  298. print '</td><td>';
  299. print '<input type="text" class="quatrevingtpercent"'.$disablededit.' name="transvalue" id="transvalue" value="'.(!empty($transvalue) ? $transvalue : "").'">';
  300. print '</td>';
  301. print '<td class="center">';
  302. print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
  303. print '<input type="submit" class="button"'.$disabled.' value="'.$langs->trans("Add").'" name="add" title="'.dol_escape_htmltag($langs->trans("YouMustEnableTranslationOverwriteBefore")).'">';
  304. print "</td>\n";
  305. print '</tr>';
  306. // Show constants
  307. $sql = "SELECT rowid, entity, lang, transkey, transvalue";
  308. $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
  309. $sql .= " WHERE 1 = 1";
  310. $sql .= " AND entity IN (".getEntity('overwrite_trans').")";
  311. $sql .= $db->order($sortfield, $sortorder);
  312. dol_syslog("translation::select from table", LOG_DEBUG);
  313. $result = $db->query($sql);
  314. if ($result) {
  315. $num = $db->num_rows($result);
  316. $i = 0;
  317. while ($i < $num) {
  318. $obj = $db->fetch_object($result);
  319. print "\n";
  320. print '<tr class="oddeven">';
  321. print '<td>'.$obj->lang.'</td>'."\n";
  322. print '<td>';
  323. if ($action == 'edit' && $obj->rowid == GETPOST('rowid', 'int')) {
  324. print '<input type="text" class="quatrevingtpercent" name="transkey" value="'.dol_escape_htmltag($obj->transkey).'">';
  325. } else {
  326. print $obj->transkey;
  327. }
  328. print '</td>'."\n";
  329. // Value
  330. print '<td class="small">';
  331. /*print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
  332. print '<input type="hidden" name="const['.$i.'][lang]" value="'.$obj->lang.'">';
  333. print '<input type="hidden" name="const['.$i.'][name]" value="'.$obj->transkey.'">';
  334. print '<input type="text" id="value_'.$i.'" class="flat inputforupdate" size="30" name="const['.$i.'][value]" value="'.dol_escape_htmltag($obj->transvalue).'">';
  335. */
  336. if ($action == 'edit' && $obj->rowid == GETPOST('rowid', 'int')) {
  337. print '<input type="text" class="quatrevingtpercent" name="transvalue" value="'.dol_escape_htmltag($obj->transvalue).'">';
  338. } else {
  339. //print $obj->transkey.' '.$langsenfileonly->tab_translate[$obj->transkey];
  340. $titleforvalue = $langs->trans("Translation").' en_US for key '.$obj->transkey.':<br>'.($langsenfileonly->tab_translate[$obj->transkey] ? $langsenfileonly->trans($obj->transkey) : '<span class="opacitymedium">'.$langs->trans("None").'</span>');
  341. /*if ($obj->lang != 'en_US') {
  342. $titleforvalue .= '<br>'.$langs->trans("Translation").' '.$obj->lang.' '...;
  343. }*/
  344. print '<span title="'.dol_escape_htmltag($titleforvalue).'" class="classfortooltip">';
  345. print dol_escape_htmltag($obj->transvalue);
  346. print '</span>';
  347. }
  348. print '</td>';
  349. print '<td class="center">';
  350. if ($action == 'edit' && $obj->rowid == GETPOST('rowid', 'int')) {
  351. print '<input type="hidden" class="button" name="rowid" value="'.$obj->rowid.'">';
  352. print '<input type="submit" class="button buttongen button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  353. print ' &nbsp; ';
  354. print '<input type="submit" class="button buttongen button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  355. } else {
  356. print '<a class="reposition editfielda paddingrightonly" href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$obj->entity.'&mode='.urlencode($mode).'&action=edit&token='.newToken().((empty($user->entity) && $debug) ? '&debug=1' : '').'">'.img_edit().'</a>';
  357. print ' &nbsp; ';
  358. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?rowid='.$obj->rowid.'&entity='.$obj->entity.'&mode='.urlencode($mode).'&action=delete&token='.newToken().((empty($user->entity) && $debug) ? '&debug=1' : '').'">'.img_delete().'</a>';
  359. }
  360. print '</td>';
  361. print "</tr>\n";
  362. print "\n";
  363. $i++;
  364. }
  365. }
  366. print '</table>';
  367. print '</div>';
  368. }
  369. if ($mode == 'searchkey') {
  370. $nbempty = 0;
  371. //var_dump($langcode);
  372. //var_dump($transkey);
  373. //var_dump($transvalue);
  374. if (empty($langcode) || $langcode == '-1') {
  375. $nbempty++;
  376. }
  377. if (empty($transkey)) {
  378. $nbempty++;
  379. }
  380. if (empty($transvalue)) {
  381. $nbempty++;
  382. }
  383. if ($action == 'search' && ($nbempty > 999)) { // 999 to disable this
  384. setEventMessages($langs->trans("WarningAtLeastKeyOrTranslationRequired"), null, 'warnings');
  385. } else {
  386. // Now search into translation array
  387. foreach ($newlang->tab_translate as $key => $val) {
  388. $newtranskey = preg_replace('/\$$/', '', preg_replace('/^\^/', '', $transkey));
  389. $newtranskeystart = preg_match('/^\^/', $transkey);
  390. $newtranskeyend = preg_match('/\$$/', $transkey);
  391. $regexstring = ($newtranskeystart ? '^' : '').preg_quote($newtranskey, '/').($newtranskeyend ? '$' : '');
  392. if ($transkey && !preg_match('/'.$regexstring.'/i', $key)) {
  393. continue;
  394. }
  395. if ($transvalue && !preg_match('/'.preg_quote($transvalue, '/').'/i', $val)) {
  396. continue;
  397. }
  398. $recordtoshow[$key] = $val;
  399. }
  400. }
  401. //print '<br>';
  402. $nbtotalofrecordswithoutfilters = count($newlang->tab_translate);
  403. $nbtotalofrecords = count($recordtoshow);
  404. $num = $limit + 1;
  405. if (($offset + $num) > $nbtotalofrecords) {
  406. $num = $limit;
  407. }
  408. //print 'param='.$param.' $_SERVER["PHP_SELF"]='.$_SERVER["PHP_SELF"].' num='.$num.' page='.$page.' nbtotalofrecords='.$nbtotalofrecords." sortfield=".$sortfield." sortorder=".$sortorder;
  409. $title = $langs->trans("Translation");
  410. if ($nbtotalofrecords > 0) {
  411. $title .= ' <span class="opacitymedium colorblack paddingleft">('.$nbtotalofrecords.' / '.$nbtotalofrecordswithoutfilters.' - <span title="'.dol_escape_htmltag(($nbtotaloffiles - $nbtotaloffilesexternal).' core - '.($nbtotaloffilesexternal).' external').'">'.$nbtotaloffiles.' '.$langs->trans("Files").'</span>)</span>';
  412. }
  413. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, -1 * $nbtotalofrecords, '', 0, '', '', $limit, 0, 0, 1);
  414. $massactionbutton = '';
  415. print '<input type="hidden" id="action" name="action" value="search">';
  416. print '<input type="hidden" id="mode" name="mode" value="'.$mode.'">';
  417. print '<div class="div-table-responsive-no-min">';
  418. print '<table class="noborder centpercent">';
  419. print '<tr class="liste_titre_filter"><td>';
  420. //print $formadmin->select_language($langcode,'langcode',0,null,$langs->trans("All"),0,0,'',1);
  421. print $formadmin->select_language($langcode, 'langcode', 0, null, 0, 0, 0, 'maxwidth250', 1);
  422. print '</td>'."\n";
  423. print '<td>';
  424. print '<input type="text" class="flat maxwidthonsmartphone" name="transkey" value="'.dol_escape_htmltag($transkey).'">';
  425. print '</td><td>';
  426. print '<input type="text" class="quatrevingtpercent" name="transvalue" value="'.dol_escape_htmltag($transvalue).'">';
  427. // Limit to superadmin
  428. /*if (isModEnabled('multicompany') && !$user->entity)
  429. {
  430. print '</td><td>';
  431. print '<input type="text" class="flat" size="1" name="entitysearch" value="'.$conf->entity.'">';
  432. }
  433. else
  434. {*/
  435. print '<input type="hidden" name="entitysearch" value="'.$conf->entity.'">';
  436. //}
  437. print '</td>';
  438. // Action column
  439. print '<td class="right nowraponall">';
  440. $searchpicto = $form->showFilterAndCheckAddButtons(!empty($massactionbutton) ? 1 : 0, 'checkforselect', 1);
  441. print $searchpicto;
  442. print '</td>';
  443. print '</tr>';
  444. print '<tr class="liste_titre">';
  445. print_liste_field_titre("Language_en_US_es_MX_etc", $_SERVER["PHP_SELF"], 'lang,transkey', '', $param, '', $sortfield, $sortorder);
  446. print_liste_field_titre("Key", $_SERVER["PHP_SELF"], 'transkey', '', $param, '', $sortfield, $sortorder);
  447. print_liste_field_titre("CurrentTranslationString", $_SERVER["PHP_SELF"], 'transvalue', '', $param, '', $sortfield, $sortorder);
  448. //if (isModEnabled('multicompany') && !$user->entity) print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], 'entity,transkey', '', $param, '', $sortfield, $sortorder);
  449. print '<td align="center"></td>';
  450. print "</tr>\n";
  451. if ($sortfield == 'transkey' && strtolower($sortorder) == 'asc') {
  452. ksort($recordtoshow);
  453. }
  454. if ($sortfield == 'transkey' && strtolower($sortorder) == 'desc') {
  455. krsort($recordtoshow);
  456. }
  457. if ($sortfield == 'transvalue' && strtolower($sortorder) == 'asc') {
  458. asort($recordtoshow);
  459. }
  460. if ($sortfield == 'transvalue' && strtolower($sortorder) == 'desc') {
  461. arsort($recordtoshow);
  462. }
  463. // Show result
  464. $i = 0;
  465. foreach ($recordtoshow as $key => $val) {
  466. $i++;
  467. if ($i <= $offset) {
  468. continue;
  469. }
  470. if ($i > ($offset + $limit)) {
  471. break;
  472. }
  473. print '<tr class="oddeven"><td>'.$langcode.'</td><td>'.$key.'</td><td class="small">';
  474. $titleforvalue = $langs->trans("Translation").' en_US for key '.$key.':<br>'.(!empty($langsenfileonly->tab_translate[$key]) ? $langsenfileonly->trans($key) : '<span class="opacitymedium">'.$langs->trans("None").'</span>');
  475. print '<span title="'.dol_escape_htmltag($titleforvalue).'" class="classfortooltip">';
  476. print dol_escape_htmltag($val);
  477. print '</span>';
  478. print '</td>';
  479. print '<td class="right nowraponall">';
  480. if (!empty($newlangfileonly->tab_translate[$key])) {
  481. if ($val != $newlangfileonly->tab_translate[$key]) {
  482. // retrieve rowid
  483. $sql = "SELECT rowid";
  484. $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
  485. $sql .= " WHERE entity IN (".getEntity('overwrite_trans').")";
  486. $sql .= " AND transkey = '".$db->escape($key)."'";
  487. dol_syslog("translation::select from table", LOG_DEBUG);
  488. $result = $db->query($sql);
  489. if ($result) {
  490. $obj = $db->fetch_object($result);
  491. }
  492. 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>';
  493. print ' ';
  494. 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>';
  495. print '&nbsp;&nbsp;';
  496. $htmltext = $langs->trans("OriginalValueWas", '<i>'.$newlangfileonly->tab_translate[$key].'</i>');
  497. print $form->textwithpicto('', $htmltext, 1, 'info');
  498. } elseif (getDolGlobalString('MAIN_ENABLE_OVERWRITE_TRANSLATION')) {
  499. //print $key.'-'.$val;
  500. print '<a class="reposition paddingrightonly" href="'.$_SERVER['PHP_SELF'].'?mode=overwrite&langcode='.urlencode($langcode).'&transkey='.urlencode($key).'">'.img_edit_add($langs->trans("TranslationOverwriteKey")).'</a>';
  501. }
  502. if (getDolGlobalInt('MAIN_FEATURES_LEVEL')) {
  503. $transifexlangfile = '$'; // $ means 'All'
  504. //$transifexurl = 'https://www.transifex.com/dolibarr-association/dolibarr/translate/#'.$langcode.'/'.$transifexlangfile.'?key='.$key;
  505. $transifexurl = 'https://www.transifex.com/dolibarr-association/dolibarr/translate/#'.$langcode.'/'.$transifexlangfile.'?q=key%3A'.$key;
  506. print ' &nbsp; <a href="'.$transifexurl.'" target="transifex">'.img_picto($langs->trans('FixOnTransifex'), 'globe').'</a>';
  507. }
  508. } else {
  509. // retrieve rowid
  510. $sql = "SELECT rowid";
  511. $sql .= " FROM ".MAIN_DB_PREFIX."overwrite_trans";
  512. $sql .= " WHERE entity IN (".getEntity('overwrite_trans').")";
  513. $sql .= " AND transkey = '".$db->escape($key)."'";
  514. dol_syslog("translation::select from table", LOG_DEBUG);
  515. $result = $db->query($sql);
  516. if ($result) {
  517. $obj = $db->fetch_object($result);
  518. }
  519. 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>';
  520. print ' ';
  521. 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>';
  522. print '&nbsp;&nbsp;';
  523. $htmltext = $langs->trans("TransKeyWithoutOriginalValue", $key);
  524. print $form->textwithpicto('', $htmltext, 1, 'warning');
  525. }
  526. /*if (isModEnabled('multicompany') && !$user->entity)
  527. {
  528. print '<td>'.$val.'</td>';
  529. }*/
  530. print '</td></tr>'."\n";
  531. }
  532. if (empty($recordtoshow)) {
  533. print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  534. }
  535. print '</table>';
  536. print '</div>';
  537. }
  538. print dol_get_fiche_end();
  539. print "</form>\n";
  540. if (!empty($langcode)) {
  541. dol_set_focus('#transvalue');
  542. }
  543. // End of page
  544. llxFooter();
  545. $db->close();