Skip to content

Commit

Permalink
Enhance performance of option MAIN_OVERWRITE_TRANS_
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Sep 17, 2015
1 parent 9cbd236 commit 8ff41a8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Expand Up @@ -9,6 +9,13 @@ Upgrading to any other version or any other database system is abolutely require
make a Dolibarr upgrade.


***** ChangeLog for 3.9 compared to 3.8.* *****

WARNING: Following changes may create regression for some external modules, but were necessary to make
Dolibarr better:
- Deprecated hidden option MAIN_USE_CUSTOM_TRANSLATION has been removed. Use MAIN_OVERWRITE_TRANS_xx_YY instead.


***** ChangeLog for 3.8 compared to 3.7.* *****
For users:
FIX: #2519
Expand Down
30 changes: 15 additions & 15 deletions htdocs/core/class/translate.class.php
Expand Up @@ -144,7 +144,6 @@ function getDefaultLang($mode=0)
* If data for file already loaded, do nothing.
* All data in translation array are stored in UTF-8 format.
* tab_loaded is completed with $domain key.
* Warning: MAIN_USE_CUSTOM_TRANSLATION is an old deprecated feature. Do not use it. It will revert
* rule "we keep first entry found with we keep last entry found" so it is probably not what you want to do.
*
* Value for hash are: 1:Loaded from disk, 2:Not found, 3:Loaded from cache
Expand Down Expand Up @@ -261,7 +260,7 @@ function Load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='')
$tab=explode('=',$line,2);
$key=trim($tab[0]);
//print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>";
if ((! empty($conf->global->MAIN_USE_CUSTOM_TRANSLATION) || empty($this->tab_translate[$key])) && isset($tab[1])) // If translation was already found, we must not continue, even if MAIN_FORCELANGDIR is set (MAIN_FORCELANGDIR is to replace lang dir, not to overwrite entries)
if (empty($this->tab_translate[$key]) && isset($tab[1])) // If translation was already found, we must not continue, even if MAIN_FORCELANGDIR is set (MAIN_FORCELANGDIR is to replace lang dir, not to overwrite entries)
{
$value=trim(preg_replace('/\\n/',"\n",$tab[1]));

Expand Down Expand Up @@ -297,7 +296,7 @@ function Load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='')
}
}

if (empty($conf->global->MAIN_FORCELANGDIR) && empty($conf->global->MAIN_USE_CUSTOM_TRANSLATION)) break; // Break loop on each root dir. If a module has forced dir, we do not stop loop.
if (empty($conf->global->MAIN_FORCELANGDIR)) break; // Break loop on each root dir. If a module has forced dir, we do not stop loop.
}
}
}
Expand Down Expand Up @@ -330,6 +329,19 @@ function Load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='')
if (empty($this->_tab_loaded[$newdomain])) $this->_tab_loaded[$newdomain]=2; // Marque ce fichier comme non trouve
}


// Overwrite translation
$overwritekey='MAIN_OVERWRITE_TRANS_'.$this->defaultlang;
if (! empty($conf->global->$overwritekey)) // Overwrite translation with key1:newstring1,key2:newstring2
{
$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"])
&& $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) $this->tab_translate["SeparatorThousand"]='';
Expand Down Expand Up @@ -410,18 +422,6 @@ function trans($key, $param1='', $param2='', $param3='', $param4='', $maxsize=0)
{
$str=$this->tab_translate[$key];

// Overwrite translation (TODO Move this at a higher level when we load tab_translate to avoid doing it for each trans call)
$overwritekey='MAIN_OVERWRITE_TRANS_'.$this->defaultlang;
if (! empty($conf->global->$overwritekey)) // Overwrite translation with key1:newstring1,key2:newstring2
{
$tmparray=explode(',', $conf->global->$overwritekey);
foreach($tmparray as $tmp)
{
$tmparray2=explode(':',$tmp);
if ($tmparray2[0]==$key) { $str=$tmparray2[1]; break; }
}
}

if (! preg_match('/^Format/',$key))
{
//print $str;
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/menus/standard/eldy.lib.php
Expand Up @@ -629,7 +629,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) $newmenu->add("/contact/list.php?leftmenu=contacts&type=p", $langs->trans("Prospects"), 2, $user->rights->societe->contact->lire);
if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $newmenu->add("/contact/list.php?leftmenu=contacts&type=c", $langs->trans("Customers"), 2, $user->rights->societe->contact->lire);
if (! empty($conf->fournisseur->enabled)) $newmenu->add("/contact/list.php?leftmenu=contacts&type=f", $langs->trans("Suppliers"), 2, $user->rights->societe->contact->lire);
$newmenu->add("/contact/list.php?leftmenu=contacts&type=o", $langs->trans("Others"), 2, $user->rights->societe->contact->lire);
$newmenu->add("/contact/list.php?leftmenu=contacts&type=o", $langs->trans("ContactOthers"), 2, $user->rights->societe->contact->lire);
//$newmenu->add("/contact/list.php?userid=$user->id", $langs->trans("MyContacts"), 1, $user->rights->societe->contact->lire);

// Categories
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/companies.lang
Expand Up @@ -338,6 +338,7 @@ ProspectLevel=Prospect potential
ContactPrivate=Private
ContactPublic=Shared
ContactVisibility=Visibility
ContactOthers=Other
OthersNotLinkedToThirdParty=Others, not linked to a third party
ProspectStatus=Prospect status
PL_NONE=None
Expand Down

0 comments on commit 8ff41a8

Please sign in to comment.