diff --git a/htdocs/admin/translation.php b/htdocs/admin/translation.php index 8d959a9decb..5e6d242dffc 100644 --- a/htdocs/admin/translation.php +++ b/htdocs/admin/translation.php @@ -23,6 +23,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; $langs->load("companies"); @@ -36,10 +37,12 @@ if (!$user->admin) accessforbidden(); $id=GETPOST('rowid','int'); $action=GETPOST('action','alpha'); + $langcode=GETPOST('langcode','alpha'); $transkey=GETPOST('transkey','alpha'); $transvalue=GETPOST('transvalue','alpha'); + $mode = GETPOST('mode')?GETPOST('mode'):'overwrite'; $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; @@ -131,82 +134,44 @@ print load_fiche_titre($langs->trans("Translation"),'','title_setup'); print $langs->trans("TranslationDesc")."
\n"; print "
\n"; -print $langs->trans("CurrentUserLanguage").': '.$langs->defaultlang.'
'; +$current_language_code=$langs->defaultlang; +$s=picto_from_langcode($current_language_code); +print $langs->trans("CurrentUserLanguage").': '.$s.' '.$current_language_code.'
'; print '
'; -print img_info().' '.$langs->trans("SomeTranslationAreUncomplete"); -$urlwikitranslatordoc='https://wiki.dolibarr.org/index.php/Translator_documentation'; -print ' ('.$langs->trans("SeeAlso").': '.$urlwikitranslatordoc.')
'; -print $langs->trans("TranslationOverwriteDesc",$langs->transnoentitiesnoconv("Language"),$langs->transnoentitiesnoconv("Key"),$langs->transnoentitiesnoconv("NewTranslationStringToShow"))."
\n"; - -print '
'; - - -$param='mode='.$mode; +$param='&mode='.$mode; +if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; +if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; +if ($optioncss != '') $param.='&optioncss='.$optioncss; +if ($langcode) $param.='&langcode='.urlencode($langcode); +if ($transkey) $param.='&transkey='.urlencode($transkey); +if ($transvalue) $param.='&transvalue='.urlencode($transvalue); print '
entity) && $debug)?'?debug=1':'').'" method="POST">'; +if ($optioncss != '') print ''; +print ''; +print ''; +print ''; +print ''; +print ''; $head=translation_prepare_head(); dol_fiche_head($head, $mode, '', 0, ''); -if ($mode == 'searchkey') -{ - //print '
'; - //print load_fiche_titre($langs->trans("TranslationKeySearch"), '', '')."\n"; - - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - if (! empty($conf->multicompany->enabled) && !$user->entity) print ''; - print ''; - print "\n"; - - // Line to search new record - $var=false; - print "\n"; - - print ''."\n"; - print ''; - // Limit to superadmin - if (! empty($conf->multicompany->enabled) && !$user->entity) - { - print ''; - print '\n"; - print ''; - - print '
'.$langs->trans("Language").' (en_US, es_MX, ...)'.$langs->trans("Key").''.$langs->trans("TranslationString").''.$langs->trans("Entity").'
'; - print $formadmin->select_language(GETPOST('langcodesearch'),'langcodesearch',0,null,$langs->trans("All"),0,0,'',1); - //print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - } - else - { - print ''; - print ''; - } - print ''; - print "
'; - print '
'; -} - if ($mode == 'overwrite') { //print load_fiche_titre($langs->trans("TranslationOverwriteKey"), '', '')."\n"; + + print img_info().' '.$langs->trans("SomeTranslationAreUncomplete"); + $urlwikitranslatordoc='https://wiki.dolibarr.org/index.php/Translator_documentation'; + print ' ('.$langs->trans("SeeAlso").': '.$urlwikitranslatordoc.')
'; + print $langs->trans("TranslationOverwriteDesc",$langs->transnoentitiesnoconv("Language"),$langs->transnoentitiesnoconv("Key"),$langs->transnoentitiesnoconv("NewTranslationStringToShow"))."\n"; + print ' ('.$langs->trans("TranslationOverwriteDesc2").').'."
\n"; + print '
'; + print ''; print ''; @@ -227,8 +192,7 @@ if ($mode == 'overwrite') print "\n"; print ''; - print $formadmin->select_language(GETPOST('langcode'),'langcode',0,null,1,0,0,'',1); - //print ''; + print $formadmin->select_language(GETPOST('langcode'), 'langcode', 0, null, 1, 0, 0, 'maxwidthonsmartphone', 1); print ''."\n"; print ''; print ''; @@ -313,6 +277,128 @@ if ($mode == 'overwrite') } +if ($mode == 'searchkey') +{ + $recordtoshow=array(); + + $nbempty=0; + /*var_dump($langcode); + var_dump($transkey); + var_dump($transvalue);*/ + if (empty($langcode) || $langcode == '-1') $nbempty++; + if (empty($transkey)) $nbempty++; + if (empty($transvalue)) $nbempty++; + if ($action == 'search' && ($nbempty > 1)) + { + setEventMessages($langs->trans("WarningAtLeastKeyOrTranslationRequired"), null, 'warnings'); + } + else + { + $newlang=new Translate('',$conf); + $newlang->setDefaultLang($langcode); + + // Load all translations keys + foreach($conf->file->dol_document_root as $keydir => $searchdir) + { + // Directory of translation files + $dir_lang = $searchdir."/langs/".$langcode; + $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'])); + $newlang->load($tmpfile, 0, 0, '', 0); + //print 'After loading lang '.$tmpfile.', newlang has '.count($newlang->tab_translate).' records
'."\n"; + } + } + + // Now search into translation array + foreach($newlang->tab_translate as $key => $val) + { + if ($transkey && ! preg_match('/'.preg_quote($transkey).'/', $key)) continue; + if ($transvalue && ! preg_match('/'.preg_quote($transvalue).'/', $val)) continue; + $recordtoshow[$key]=$val; + } + } + + //print '
'; + $nbtotalofrecordswithoutfilters = count($newlang->tab_translate); + $nbtotalofrecords = count($recordtoshow); + $num = $limit + 1; + if (($offset + $num) > $nbtotalofrecords) $num = $limit; + + //print 'param='.$param.' $_SERVER["PHP_SELF"]='.$_SERVER["PHP_SELF"].' num='.$num.' page='.$page.' nbtotalofrecords='.$nbtotalofrecords." sortfield=".$sortfield." sortorder=".$sortorder; + $title = $langs->trans("TranslationKeySearch"); + if ($nbtotalofrecords > 0) $title.=' ('.$nbtotalofrecords.' / '.$nbtotalofrecordswithoutfilters.')'; + print print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, -1 * $nbtotalofrecords, '', 0, '', '', $limit)."\n"; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print_liste_field_titre($langs->trans("Language").' (en_US, es_MX, ...)',$_SERVER["PHP_SELF"],'lang,transkey','',$param,'',$sortfield,$sortorder).''; + print_liste_field_titre($langs->trans("Key"),$_SERVER["PHP_SELF"],'transkey','',$param,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("CurrentTranslationString"),$_SERVER["PHP_SELF"],'transvalue','',$param,'',$sortfield,$sortorder); + if (! empty($conf->multicompany->enabled) && !$user->entity) print_liste_field_titre($langs->trans("Entity"),$_SERVER["PHP_SELF"],'entity,transkey','',$param,'',$sortfield,$sortorder); + print ''; + print "\n"; + + // Line to search new record + $var=false; + print "\n"; + + print ''."\n"; + print ''; + // Limit to superadmin + if (! empty($conf->multicompany->enabled) && !$user->entity) + { + print ''; + print '\n"; + print ''; + + if ($sortfield == 'transkey' && strtolower($sortorder) == 'asc') ksort($recordtoshow); + if ($sortfield == 'transkey' && strtolower($sortorder) == 'desc') krsort($recordtoshow); + if ($sortfield == 'transvalue' && strtolower($sortorder) == 'asc') asort($recordtoshow); + if ($sortfield == 'transvalue' && strtolower($sortorder) == 'desc') arsort($recordtoshow); + + // Show result + $i=0; + foreach($recordtoshow as $key => $val) + { + $i++; + if ($i <= $offset) continue; + if ($i > ($offset + $limit)) break; + print ''."\n"; + } + + print '
'; + $langcode=GETPOST('langcode')?GETPOST('langcode'):$langs->defaultlang; + //print $formadmin->select_language($langcode,'langcode',0,null,$langs->trans("All"),0,0,'',1); + print $formadmin->select_language($langcode,'langcode', 0, null, 0, 0, 0, 'maxwidthonsmartphone', 1); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + else + { + print ''; + print ''; + } + print ''; + print "
'.$langcode.''.$key.''; + print dol_escape_htmltag($val); + print '
'; + print ''; +} + dol_fiche_end(); print "\n"; diff --git a/htdocs/core/class/html.formadmin.class.php b/htdocs/core/class/html.formadmin.class.php index af51b64fa8d..16a16719366 100644 --- a/htdocs/core/class/html.formadmin.class.php +++ b/htdocs/core/class/html.formadmin.class.php @@ -58,7 +58,7 @@ class FormAdmin * @param int $showcode Add language code into label * @return string Return HTML select string with list of languages */ - function select_language($selected='',$htmlname='lang_id',$showauto=0,$filter=null,$showempty='',$showwarning=0,$disabled=0,$morecss='',$showcode=0) + function select_language($selected='', $htmlname='lang_id', $showauto=0, $filter=null, $showempty='', $showwarning=0, $disabled=0, $morecss='', $showcode=0) { global $langs; diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 9ca6196b018..6b596dc3aa5 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -155,14 +155,15 @@ class Translate * @param integer $alt 0 (try xx_ZZ then 1), 1 (try xx_XX then 2), 2 (try en_US) * @param int $stopafterdirection Stop when the DIRECTION tag is found (optimize speed) * @param int $forcelangdir To force a different lang directory + * @param int $loadfromfileonly 1=Do not load overwritten translation from file or old conf. * @return int <0 if KO, 0 if already loaded or loading not required, >0 if OK */ - function load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='') + function load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='',$loadfromfileonly=0) { global $conf,$db; // Load $this->tab_translate[] from database - if (count($this->tab_translate) == 0) $this->loadFromDatabase($db); // Nothing was loaded yet, so we load database. + if (empty($loadfromfileonly) && count($this->tab_translate) == 0) $this->loadFromDatabase($db); // Nothing was loaded yet, so we load database. // Check parameters if (empty($domain)) @@ -336,19 +337,20 @@ class Translate // This part is deprecated and replaced with table llx_overwrite_trans // Kept for backward compatibility. - $overwritekey='MAIN_OVERWRITE_TRANS_'.$this->defaultlang; - if (! empty($conf->global->$overwritekey)) // Overwrite translation with key1:newstring1,key2:newstring2 - { - // Overwrite translation with param MAIN_OVERWRITE_TRANS_xx_XX - $tmparray=explode(',', $conf->global->$overwritekey); - foreach($tmparray as $tmp) + if (empty($loadfromfileonly)) + { + $overwritekey='MAIN_OVERWRITE_TRANS_'.$this->defaultlang; + if (! empty($conf->global->$overwritekey)) // Overwrite translation with key1:newstring1,key2:newstring2 { - $tmparray2=explode(':',$tmp); - if (! empty($tmparray2[1])) $this->tab_translate[$tmparray2[0]]=$tmparray2[1]; + // Overwrite translation with param MAIN_OVERWRITE_TRANS_xx_XX + $tmparray=explode(',', $conf->global->$overwritekey); + foreach($tmparray as $tmp) + { + $tmparray2=explode(':',$tmp); + if (! empty($tmparray2[1])) $this->tab_translate[$tmparray2[0]]=$tmparray2[1]; + } } - } - - + } // Check to be sure that SeparatorDecimal differs from SeparatorThousand if (! empty($this->tab_translate["SeparatorDecimal"]) && ! empty($this->tab_translate["SeparatorThousand"]) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 5065abc69ed..4d6f05f4de8 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3041,7 +3041,7 @@ function load_fiche_titre($titre, $mesg='', $picto='title_generic.png', $pictois * @param string $sortorder Order to sort ('' by default) * @param string $center Strin gin the middle ('' by default). We often find here string $massaction comming from $form->selectMassAction() * @param int $num Number of records found by select with limit+1 - * @param int $totalnboflines Total number of records/lines for all pages (if known). Use a negative value to no show number. + * @param int $totalnboflines Total number of records/lines for all pages (if known). Use a negative value to not show number. * @param string $picto Icon to use before title (should be a 32x32 transparent png file) * @param int $pictoisfullpath 1=Icon name is a full absolute url of image * @param string $morehtml More html to show diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index aebb4aaa81d..4549aa74181 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1041,8 +1041,11 @@ TranslationSetup=Setup of translation TranslationKeySearch=Search a translation key or string TranslationOverwriteKey=Overwrite a translation string TranslationDesc=How to set displayed application language :
* Systemwide: menu Home - Setup - Display
* Per user: User display setup tab of user card (click on username at the top of the screen). -TranslationOverwriteDesc=You can also override strings filling the following table. Choose your language from "%s" dropdown, insert the key string found in the lang file (langs/xx_XX/somefile.lang) into "%s" and your new translation into "%s". +TranslationOverwriteDesc=You can also override strings filling the following table. Choose your language from "%s" dropdown, insert the translation key string into "%s" and your new translation into "%s" +TranslationOverwriteDesc2=You can use the other tab to help you know translation key to use TranslationString=Translation string +CurrentTranslationString=Current translation string +WarningAtLeastKeyOrTranslationRequired=A search criteria is required at least for key or translation string NewTranslationStringToShow=New translation string to show TotalNumberOfActivatedModules=Total number of activated feature modules: %s / %s YouMustEnableOneModule=You must at least enable 1 module