Skip to content
Snippets Groups Projects
Commit 53661e1e authored by Laurent Destailleur's avatar Laurent Destailleur Committed by GitHub
Browse files

Merge pull request #6211 from GPCsolutions/optimizetranslate

[Qual] Optimize language file loading
parents 9d3c7741 ac92e23b
No related branches found
No related tags found
No related merge requests found
...@@ -256,32 +256,33 @@ class Translate ...@@ -256,32 +256,33 @@ class Translate
{ {
if ($usecachekey) $tabtranslatedomain=array(); // To save lang content in cache if ($usecachekey) $tabtranslatedomain=array(); // To save lang content in cache
while ($line = fgets($fp,4096)) // Ex: Need 225ms for all fgets on all lang file for Third party page. Same speed than file_get_contents /**
{ * Read each lines until a '=' (with any combination of spaces around it)
if ($line[0] != "\n" && $line[0] != " " && $line[0] != "#") * and split the rest until a line feed.
{ * This is more efficient than fgets + explode + trim by a factor of ~2.
$tab=explode('=',$line,2); */
$key=trim($tab[0]); while ($line = fscanf($fp, "%[^= ]%*[ =]%[^\n]")) {
if (isset($line[1])) {
list($key, $value) = $line;
//if ($domain == 'orders') print "Domain=$domain, found a string for $tab[0] with value $tab[1]. Currently in cache ".$this->tab_translate[$key]."<br>"; //if ($domain == 'orders') print "Domain=$domain, found a string for $tab[0] with value $tab[1]. Currently in cache ".$this->tab_translate[$key]."<br>";
//if ($key == 'Order') print "Domain=$domain, found a string for key=$key=$tab[0] with value $tab[1]. Currently in cache ".$this->tab_translate[$key]."<br>"; //if ($key == 'Order') print "Domain=$domain, found a string for key=$key=$tab[0] with value $tab[1]. Currently in cache ".$this->tab_translate[$key]."<br>";
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) if (empty($this->tab_translate[$key])) { // 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 = preg_replace('/\\n/', "\n", $value); // Parse and render carriage returns
$value=trim(preg_replace('/\\n/',"\n",$tab[1])); if ($key == 'DIRECTION') { // This is to declare direction of language
if ($alt < 2 || empty($this->tab_translate[$key])) { // We load direction only for primary files or if not yet loaded
if ($key == 'DIRECTION') // This is to declare direction of language
{
if ($alt < 2 || empty($this->tab_translate[$key])) // We load direction only for primary files or if not yet loaded
{
$this->tab_translate[$key] = $value; $this->tab_translate[$key] = $value;
if ($stopafterdirection) break; // We do not save tab if we stop after DIRECTION if ($stopafterdirection) {
else if ($usecachekey) $tabtranslatedomain[$key]=$value; break; // We do not save tab if we stop after DIRECTION
} elseif ($usecachekey) {
$tabtranslatedomain[$key] = $value;
} }
} }
else } else {
{
$this->tab_translate[$key] = $value; $this->tab_translate[$key] = $value;
//if ($domain == 'orders') print "$tab[0] value $value<br>"; //if ($domain == 'orders') print "$tab[0] value $value<br>";
if ($usecachekey) $tabtranslatedomain[$key]=$value; // To save lang content in cache if ($usecachekey) {
$tabtranslatedomain[$key] = $value;
} // To save lang content in cache
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment