Issues

ZF-6671: Different results between 1.7.4 and 1.8.1

Issue Type: Bug Created: 2009-05-15T03:55:19.000+0000 Last Updated: 2009-07-20T12:11:54.000+0000 Status: Resolved Fix version(s): - 1.9.0 (31/Jul/09)

Reporter: Jan Pieper (jpieper) Assignee: Thomas Weidner (thomas) Tags: - Zend_Translate

Related issues: Attachments:

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.

<pre class="highlight"><?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 


<pre class="highlight"><?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

Comments

Posted by Thomas Weidner (thomas) on 2009-05-15T04:18:12.000+0000

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.

Posted by Jan Pieper (jpieper) on 2009-05-15T04:45:59.000+0000

So it won't be able anymore?

Posted by Thomas Weidner (thomas) on 2009-05-15T05:16:30.000+0000

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".

Posted by Jan Pieper (jpieper) on 2009-05-15T11:47:11.000+0000

<pre class="highlight">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) {

Posted by Thomas Weidner (thomas) on 2009-06-27T10:19:54.000+0000

In Incubator since r16321, waiting for code review of r16247

Posted by Thomas Weidner (thomas) on 2009-07-20T12:11:54.000+0000

Accepted and integrated into core with r16883.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts