Issues

ZF-11112: Zend_Translate_Adapter emits notice when 'content' option is not provided to addTranslation()

Description

In Line 227 of abstract Zend_Translate_Adapter the options array evaluated of the key 'content'

if (!($options['content'] instanceof Zend_Translate) && !($options['content'] instanceof Zend_Translate_Adapter)) { ...
}

When the key is not defined as index in options, php throws a notice

Notice: Undefined index: content in /home/ronny/svn/trunk/library/vendor/sources/ZendFramework-1.11.1-minimal/library/Zend/Translate/Adapter.php on line 227

better is to check if the key exists

if (array_key_exists($options['content']) && !($options['content'] instanceof Zend_Translate) && !($options['content'] instanceof Zend_Translate_Adapter)) { ...
}

Comments

'content' must always be given by the adapter as this is the translation content itself.

It is impossible that 'content' is not given because this would mean that you have nothing to translate. An empty translation object is not allowed as it would always return a warning as no single language would exist.

The adapter must in this case throw an exception.

It's been more than a month with no response from original reporter, so I have marked issue as resolved, not an issue.

Just a thought: Would it be a good idea to enforce the requirement of supplying a 'content' key? ie:


Index: library/Zend/Translate/Adapter.php
===================================================================
--- library/Zend/Translate/Adapter.php  (revision 23914)
+++ library/Zend/Translate/Adapter.php  (working copy)
@@ -212,6 +212,11 @@
         } else if (!is_array($options)) {
             $options = array('content' => $options);
         }
+
+        if (!isset($options['content']) || empty($options['content'])) {
+            require_once 'Zend/Translate/Exception.php';
+            throw new Zend_Translate_Exception("Required option 'content' is missing");
+        }

         $originate = null;
         if (!empty($options['locale'])) {

Reopening issue and changing to improvement

Fixed in trunk r23962

Adam, thnx for your fix

Please do actually not close I18n related issues as I18n is being reworked. This is intentionally Thnx

Merged to release-1.11 in r24126 Leaving issue open-unresolved and assigned to Thomas Weidner, at his request

Fixed in ZF2 with GH-278 Attached to Adam as he provided the correct patch

By requiring 'content' you seem to be insisting that custom adapters will use it. This is not always the case. I have an adapter that does real-time translation via a web service. It isn't relying on local files.

I believe it should be up to the individual adapter to decide if a certain option is required.