From f0951e317b0f4c05f4abc8780b16fe42e17b6350 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 15 Aug 2011 23:17:14 +0000 Subject: [PATCH] New: Now a module can embed its own language files. Only modified entries must be provided. --- htdocs/core/class/html.formfile.class.php | 4 +-- htdocs/core/class/translate.class.php | 42 +++++++++++++++++------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 056c0902784..764a3c49da7 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -21,7 +21,7 @@ * \file htdocs/core/class/html.formfile.class.php * \ingroup core * \brief File of class to offer components to list and upload files - * \version $Id: html.formfile.class.php,v 1.55 2011/08/11 07:41:41 hregis Exp $ + * \version $Id: html.formfile.class.php,v 1.56 2011/08/15 23:17:52 eldy Exp $ */ @@ -387,7 +387,7 @@ class FormFile $buttonlabeltoshow=$buttonlabel; if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate'); - if (empty($noform)) $out.= '
'; + if (empty($noform)) $out.= ''; $out.= ''; $out.= ''; diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 4496c18ff1f..83b72d88f50 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -23,7 +23,7 @@ * \brief File for Tanslate class * \author Eric Seigne * \author Laurent Destailleur - * \version $Id: translate.class.php,v 1.49 2011/08/01 22:03:50 eldy Exp $ + * \version $Id: translate.class.php,v 1.50 2011/08/15 23:17:14 eldy Exp $ */ @@ -49,6 +49,7 @@ class Translate { /** * Constructor + * * @param dir Force directory that contains /langs subdirectory (value is sometine '..' like into install/* pages * or support/* pages). * @param conf Object with Dolibarr configuration @@ -64,6 +65,7 @@ class Translate { /** * Set accessor for this->defaultlang + * * @param srclang Language to use */ function setDefaultLang($srclang='fr_FR') @@ -76,10 +78,14 @@ class Translate { if (! empty($conf->global->MAIN_FORCELANGDIR)) { $more=array(); + $i=0; foreach($conf->file->dol_document_root as $dir) { $newdir=$dir.$conf->global->MAIN_FORCELANGDIR; - if (! in_array($newdir,$this->dir)) $more[]=$newdir; + if (! in_array($newdir,$this->dir)) + { + $more['module_'.$i]=$newdir; $i++; + } } $this->dir=array_merge($more,$this->dir); } @@ -125,6 +131,7 @@ class Translate { /** * Return active language code for current user * It's an accessor for this->defaultlang + * * @param mode 0=Long language code, 1=Short language code * @return string Language code used (en_US, en_AU, fr_FR, ...) */ @@ -141,6 +148,7 @@ class Translate { * All data in translation array are stored in UTF-8 format. * tab_loaded is completed with $domain key. * Value for hash are: 1:Loaded from disk, 2:Not found, 3:Loaded from cache + * * @param domain File name to load (.lang file). Use file@module if file is in a module directory. * @param alt 0 (try xx_ZZ then 1), 1 (try xx_XX then 2), 2 (try en_US or fr_FR or es_ES) * @param stopafterdirection Stop when the DIRECTION tag is found (optimize) @@ -151,6 +159,7 @@ class Translate { { global $conf; + //var_dump($this->dir);exit; // Check parameters if (empty($domain)) { @@ -185,7 +194,7 @@ class Translate { if ($alt < 1 && strtolower($langarray[0]) == strtolower($langarray[1])) $alt=1; if ($alt < 2 && (strtolower($langofdir) == 'en_us' || strtolower($langofdir) == 'fr_fr' || strtolower($langofdir) == 'es_es')) $alt=2; - foreach($this->dir as $searchdir) + foreach($this->dir as $keydir => $searchdir) { // If $domain is "file@module" instead of "file" then we look for module lang file // in htdocs/custom/modules/mymodule/langs/code_CODE/file.lang @@ -200,18 +209,18 @@ class Translate { $file_lang_osencoded=dol_osencode($file_lang); $filelangexists=is_file($file_lang_osencoded); - //dol_syslog('Translate::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' file_lang='.$file_lang." => ".$filelangexists); + //dol_syslog('Translate::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' file_lang='.$file_lang." => filelangexists=".$filelangexists); if ($filelangexists) { $found=false; - // Enable cache of lang file in memory (not by default) + // Enable caching of lang file in memory (not by default) $usecachekey=''; // Using a memcached server if (! empty($conf->memcached->enabled) && ! empty($conf->global->MEMCACHED_SERVER)) { - $usecachekey=$newdomain.'_'.$langofdir; + $usecachekey=$newdomain.'_'.$langofdir.'_'.$file_lang; } // Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) @@ -221,7 +230,9 @@ class Translate { if ($usecachekey) { - require_once(DOL_DOCUMENT_ROOT ."/lib/memory.lib.php"); + //dol_syslog('Translate::Load we will cache result into usecachekey '.$usecachekey); + + require_once(DOL_DOCUMENT_ROOT ."/lib/memory.lib.php"); $tmparray=dol_getcache($usecachekey); if (is_array($tmparray) && sizeof($tmparray)) { @@ -288,7 +299,8 @@ class Translate { $size=dol_setcache($usecachekey,$tabtranslatedomain); } //exit; - break; // Break loop on each root dir + + if (empty($conf->global->MAIN_FORCELANGDIR)) break; // Break loop on each root dir. If a module has forced, we do not stop loop. } } } @@ -375,6 +387,7 @@ class Translate { * Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif * et si toujours pas trouve, il est retourne tel quel * Les parametres de cette methode peuvent contenir de balises HTML. + * * @param key cle de chaine a traduire * @param param1 chaine de param1 * @param param2 chaine de param2 @@ -418,6 +431,7 @@ class Translate { * Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif * et si toujours pas trouve, il est retourne tel quel. * Parameters of this method must not contains any HTML tags. + * * @param key key of string to translate * @param param1 chaine de param1 * @param param2 chaine de param2 @@ -446,6 +460,7 @@ class Translate { * et si toujours pas trouve, il est retourne tel quel. * No convert to encoding charset of lang object is done. * Parameters of this method must not contains any HTML tags. + * * @param key key of string to translate * @param param1 chaine de param1 * @param param2 chaine de param1 @@ -470,6 +485,7 @@ class Translate { /** * Return translation of a key depending on country + * * @param str string root to translate * @param countrycode country code (FR, ...) * @return string translated string @@ -483,6 +499,7 @@ class Translate { /** * Retourne la version traduite du texte passe en parametre complete du code pays + * * @param str string root to translate * @param countrycode country code (FR, ...) * @return string translated string @@ -496,6 +513,7 @@ class Translate { /** * Convert a string into output charset (this->charset_output that should be defined to conf->file->character_set_client) + * * @param str String to convert * @param pagecodefrom Page code of src string * @return string Converted string @@ -510,6 +528,7 @@ class Translate { /** * Return list of all available languages + * * @param langdir Directory to scan * @param maxlength Max length for each value in combo box (will be truncated) * @param usecode Show code instead of country name for language variant @@ -544,6 +563,7 @@ class Translate { /** * Return if a filename $filename exists for current language (or alternate language) + * * @param filename Language filename to search * @param searchalt Search also alernate language file * @return boolean true if exists and readable @@ -571,7 +591,8 @@ class Translate { /** * Return full text translated to language label for a key. Store key-label in a cache. * This function need module "numberwords" to be installed. If not it will return - * same number (this module is not provided by default as it use non GPL source code). + * same number (this module is not provided by default as it use non GPL source code). + * * @param number Number to encode in full text * @param isamount 1=It's an amount, 0=it's just a number * @return string Label translated in UTF8 (but without entities) @@ -608,13 +629,14 @@ class Translate { /** * Return a label for a key. Store key-label into cache variable $this->cache_labels to save SQL requests to get labels. + * This function can be used to get label in database but more often to get code from key id. + * * @param db Database handler * @param key Key to get label (key in language file) * @param tablename Table name without prefix * @param fieldkey Field for key * @param fieldlabel Field for label * @return string Label in UTF8 (but without entities) - * @remarks This function can be used to get label in database but more often to get code from key id. */ function getLabelFromKey($db,$key,$tablename,$fieldkey,$fieldlabel) {