Zend Framework

Different results between 1.7.4 and 1.8.1

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.8.1
  • Fix Version/s: 1.9.0
  • Component/s: Zend_Translate
  • Labels:
    None

Description

We are running an application on ZF 1.7.4 and I updated the version on our test environment to 1.8.1. I found a difference between these two versions in overwriting translations.

Zend Framework 1.7.4
<?php

require_once 'Zend/Translate.php';
$translate = new Zend_Translate('Gettext', 'application/lang/de.mo', 'de');
echo $translate->_('hello'); // hallo welt

$translate->addTranslation('module/dummy/lang/de.mo', 'de');
echo $translate->_('hello'); // hallo
Zend Framework 1.8.1
<?php

require_once 'Zend/Translate.php';
$translate = new Zend_Translate('Gettext', 'application/lang/de.mo', 'de');
echo $translate->_('hello'); // hallo welt

$translate->addTranslation('module/dummy/lang/de.mo', 'de');
echo $translate->_('hello'); // hallo welt

Activity

Hide
Thomas Weidner added a comment -

Using the same messageId within several files, and loading them at once leads always to unexpected behaviour. What you will get returned depends on the set cache, the search order and several other informations.

Show
Thomas Weidner added a comment - Using the same messageId within several files, and loading them at once leads always to unexpected behaviour. What you will get returned depends on the set cache, the search order and several other informations.
Hide
Jan Pieper added a comment -

So it won't be able anymore?

Show
Jan Pieper added a comment - So it won't be able anymore?
Hide
Thomas Weidner added a comment -

I didn't say such.

The main reason for this behaviour is that before 1.8 the adapter was responsible for loading the data, adding the entries in the cache. But this introduced problems as adapters didn't behave 100% same and made also problems with caching multi-locale files.

So we unified this. Now all work is done in the abstract class and therefor is unified for all adapters.

For now you won't be able to change this.
For future I could imagine to add a option which switches between "don't overwrite duplicate messageIds" and "overwrite duplicate messageIds".

Show
Thomas Weidner added a comment - I didn't say such. The main reason for this behaviour is that before 1.8 the adapter was responsible for loading the data, adding the entries in the cache. But this introduced problems as adapters didn't behave 100% same and made also problems with caching multi-locale files. So we unified this. Now all work is done in the abstract class and therefor is unified for all adapters. For now you won't be able to change this. For future I could imagine to add a option which switches between "don't overwrite duplicate messageIds" and "overwrite duplicate messageIds".
Hide
Jan Pieper added a comment -
Index: Adapter.php
===================================================================
--- Adapter.php	(revision 15595)
+++ Adapter.php	(working copy)
@@ -74,7 +74,8 @@
         'log'             => null,
         'logMessage'      => "Untranslated message within '%locale%': %message%",
         'logUntranslated' => false,
-        'scan'            => null
+        'scan'            => null,
+        'merge'           => false
     );
 
     /**
@@ -473,8 +474,12 @@
             if (!isset($this->_translate[$key])) {
                 $this->_translate[$key] = array();
             }
-
-            $this->_translate[$key] = $this->_translate[$key] + $temp[$key];
+            
+            if ($this->_options['merge']) {
+                $this->_translate[$key] = array_merge($this->_translate[$key], $temp[$key]);
+            } else {
+                $this->_translate[$key] = $this->_translate[$key] + $temp[$key];
+            }
         }
 
         if ($this->_automatic === true) {
Show
Jan Pieper added a comment -
Index: Adapter.php
===================================================================
--- Adapter.php	(revision 15595)
+++ Adapter.php	(working copy)
@@ -74,7 +74,8 @@
         'log'             => null,
         'logMessage'      => "Untranslated message within '%locale%': %message%",
         'logUntranslated' => false,
-        'scan'            => null
+        'scan'            => null,
+        'merge'           => false
     );
 
     /**
@@ -473,8 +474,12 @@
             if (!isset($this->_translate[$key])) {
                 $this->_translate[$key] = array();
             }
-
-            $this->_translate[$key] = $this->_translate[$key] + $temp[$key];
+            
+            if ($this->_options['merge']) {
+                $this->_translate[$key] = array_merge($this->_translate[$key], $temp[$key]);
+            } else {
+                $this->_translate[$key] = $this->_translate[$key] + $temp[$key];
+            }
         }
 
         if ($this->_automatic === true) {
Hide
Thomas Weidner added a comment -

In Incubator since r16321, waiting for code review of r16247

Show
Thomas Weidner added a comment - In Incubator since r16321, waiting for code review of r16247
Hide
Thomas Weidner added a comment -

Accepted and integrated into core with r16883.

Show
Thomas Weidner added a comment - Accepted and integrated into core with r16883.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: