translation.php 25 KB

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