diff --git a/htdocs/admin/translation.php b/htdocs/admin/translation.php
index 93f62337746..bb42808ebd4 100644
--- a/htdocs/admin/translation.php
+++ b/htdocs/admin/translation.php
@@ -254,6 +254,60 @@ $head = translation_prepare_head();
print dol_get_fiche_head($head, $mode, '', -1, '');
+
+$langcode = GETPOSTISSET('langcode') ? GETPOST('langcode') : $langs->defaultlang;
+
+$newlang = new Translate('', $conf);
+$newlang->setDefaultLang($langcode);
+
+$langsenfileonly = new Translate('', $conf);
+$langsenfileonly->setDefaultLang('en_US');
+
+$newlangfileonly = new Translate('', $conf);
+$newlangfileonly->setDefaultLang($langcode);
+
+$recordtoshow = array();
+
+// Search modules dirs
+$modulesdir = dolGetModulesDirs();
+
+$nbtotaloffiles = 0;
+
+// Search into dir of modules (the $modulesdir is already a list that loop on $conf->file->dol_document_root)
+$i = 0;
+foreach ($modulesdir as $keydir => $tmpsearchdir) {
+ $searchdir = $tmpsearchdir; // $searchdir can be '.../htdocs/core/modules/' or '.../htdocs/custom/mymodule/core/modules/'
+
+ // Directory of translation files
+ $dir_lang = dirname(dirname($searchdir))."/langs/".$langcode; // The 2 dirname is to go up in dir for 2 levels
+ $dir_lang_osencoded = dol_osencode($dir_lang);
+
+ $filearray = dol_dir_list($dir_lang_osencoded, 'files', 0, '', '', $sortfield, (strtolower($sortorder) == 'asc' ?SORT_ASC:SORT_DESC), 1);
+ foreach ($filearray as $file) {
+ $tmpfile = preg_replace('/.lang/i', '', basename($file['name']));
+ $moduledirname = (basename(dirname(dirname($dir_lang))));
+
+ $langkey = $tmpfile;
+ if ($i > 0) {
+ $langkey .= '@'.$moduledirname;
+ }
+ //var_dump($i.' - '.$keydir.' - '.$dir_lang_osencoded.' -> '.$moduledirname . ' / ' . $tmpfile.' -> '.$langkey);
+
+ $result = $newlang->load($langkey, 0, 0, '', 0); // Load translation files + database overwrite
+ $result = $newlangfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
+ if ($result < 0) {
+ print 'Failed to load language file '.$tmpfile.'
'."\n";
+ } else {
+ $nbtotaloffiles++;
+ }
+ //print 'After loading lang '.$langkey.', newlang has '.count($newlang->tab_translate).' records
'."\n";
+
+ $result = $langsenfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
+ }
+ $i++;
+}
+
+
if ($mode == 'overwrite') {
print '';
@@ -348,7 +402,14 @@ if ($mode == 'overwrite') {
if ($action == 'edit' && $obj->rowid == GETPOST('rowid', 'int')) {
print '';
} else {
+ //print $obj->transkey.' '.$langsenfileonly->tab_translate[$obj->transkey];
+ $titleforvalue = $langs->trans("Translation").' en_US for key '.$obj->transkey.':
'.($langsenfileonly->tab_translate[$obj->transkey] ? $langsenfileonly->trans($obj->transkey) : ''.$langs->trans("None").'');
+ /*if ($obj->lang != 'en_US') {
+ $titleforvalue .= '
'.$langs->trans("Translation").' '.$obj->lang.' '...;
+ }*/
+ print '';
print dol_escape_htmltag($obj->transvalue);
+ print '';
}
print '';
@@ -376,20 +437,6 @@ if ($mode == 'overwrite') {
}
if ($mode == 'searchkey') {
- $langcode = GETPOSTISSET('langcode') ? GETPOST('langcode') : $langs->defaultlang;
-
- $newlang = new Translate('', $conf);
- $newlang->setDefaultLang($langcode);
-
- $newlangfileonly = new Translate('', $conf);
- $newlangfileonly->setDefaultLang($langcode);
-
- $recordtoshow = array();
-
- // Search modules dirs
- $modulesdir = dolGetModulesDirs();
-
- $nbtotaloffiles = 0;
$nbempty = 0;
/*var_dump($langcode);
var_dump($transkey);
@@ -403,41 +450,10 @@ if ($mode == 'searchkey') {
if (empty($transvalue)) {
$nbempty++;
}
+
if ($action == 'search' && ($nbempty > 999)) { // 999 to disable this
setEventMessages($langs->trans("WarningAtLeastKeyOrTranslationRequired"), null, 'warnings');
} else {
- // Search into dir of modules (the $modulesdir is already a list that loop on $conf->file->dol_document_root)
- $i = 0;
- foreach ($modulesdir as $keydir => $tmpsearchdir) {
- $searchdir = $tmpsearchdir; // $searchdir can be '.../htdocs/core/modules/' or '.../htdocs/custom/mymodule/core/modules/'
-
- // Directory of translation files
- $dir_lang = dirname(dirname($searchdir))."/langs/".$langcode; // The 2 dirname is to go up in dir for 2 levels
- $dir_lang_osencoded = dol_osencode($dir_lang);
-
- $filearray = dol_dir_list($dir_lang_osencoded, 'files', 0, '', '', $sortfield, (strtolower($sortorder) == 'asc' ?SORT_ASC:SORT_DESC), 1);
- foreach ($filearray as $file) {
- $tmpfile = preg_replace('/.lang/i', '', basename($file['name']));
- $moduledirname = (basename(dirname(dirname($dir_lang))));
-
- $langkey = $tmpfile;
- if ($i > 0) {
- $langkey .= '@'.$moduledirname;
- }
- //var_dump($i.' - '.$keydir.' - '.$dir_lang_osencoded.' -> '.$moduledirname . ' / ' . $tmpfile.' -> '.$langkey);
-
- $result = $newlang->load($langkey, 0, 0, '', 0); // Load translation files + database overwrite
- $result = $newlangfileonly->load($langkey, 0, 0, '', 1); // Load translation files only
- if ($result < 0) {
- print 'Failed to load language file '.$tmpfile.'
'."\n";
- } else {
- $nbtotaloffiles++;
- }
- //print 'After loading lang '.$langkey.', newlang has '.count($newlang->tab_translate).' records
'."\n";
- }
- $i++;
- }
-
// Now search into translation array
foreach ($newlang->tab_translate as $key => $val) {
if ($transkey && !preg_match('/'.preg_quote($transkey, '/').'/i', $key)) {
@@ -532,8 +548,12 @@ if ($mode == 'searchkey') {
break;
}
print '