translation.php 25 KB

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