Browse Source

[ZF-7941] Zend_Translate:

- allow translation without translation
(be aware that warnings are still raised at have to be switched off explicitly)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18410 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 years ago
parent
commit
b96c8d78ef

+ 5 - 4
library/Zend/Translate.php

@@ -60,13 +60,13 @@ class Zend_Translate {
      * Generates the standard translation object
      *
      * @param  string              $adapter  Adapter to use
-     * @param  array               $data     Translation source data for the adapter
+     * @param  array               $data     OPTIONAL Translation source data for the adapter
      *                                       Depends on the Adapter
      * @param  string|Zend_Locale  $locale   OPTIONAL locale to use
      * @param  array               $options  OPTIONAL options for the adapter
      * @throws Zend_Translate_Exception
      */
-    public function __construct($adapter, $data, $locale = null, array $options = array())
+    public function __construct($adapter, $data = null, $locale = null, array $options = array())
     {
         $this->setAdapter($adapter, $data, $locale, $options);
     }
@@ -75,12 +75,12 @@ class Zend_Translate {
      * Sets a new adapter
      *
      * @param  string              $adapter  Adapter to use
-     * @param  string|array        $data     Translation data
+     * @param  string|array        $data     OPTIONAL Translation data
      * @param  string|Zend_Locale  $locale   OPTIONAL locale to use
      * @param  array               $options  OPTIONAL Options to use
      * @throws Zend_Translate_Exception
      */
-    public function setAdapter($adapter, $data, $locale = null, array $options = array())
+    public function setAdapter($adapter, $data = null, $locale = null, array $options = array())
     {
         if (Zend_Loader::isReadable('Zend/Translate/Adapter/' . ucfirst($adapter). '.php')) {
             $adapter = 'Zend_Translate_Adapter_' . ucfirst($adapter);
@@ -93,6 +93,7 @@ class Zend_Translate {
         if (self::$_cache !== null) {
             call_user_func(array($adapter, 'setCache'), self::$_cache);
         }
+
         $this->_adapter = new $adapter($data, $locale, $options);
         if (!$this->_adapter instanceof Zend_Translate_Adapter) {
             require_once 'Zend/Translate/Exception.php';

+ 8 - 5
library/Zend/Translate/Adapter.php

@@ -99,14 +99,14 @@ abstract class Zend_Translate_Adapter {
     /**
      * Generates the adapter
      *
-     * @param  string|array       $data    Translation data or filename for this adapter
-     * @param  string|Zend_Locale $locale  (optional) Locale/Language to set, identical with Locale
+     * @param  string|array       $data    OPTIONAL Translation data or filename for this adapter
+     * @param  string|Zend_Locale $locale  OPTIONAL Locale/Language to set, identical with Locale
      *                                     identifiers see Zend_Locale for more information
-     * @param  array              $options (optional) Options for the adaptor
+     * @param  array              $options OPTIONAL Options for the adaptor
      * @throws Zend_Translate_Exception
      * @return void
      */
-    public function __construct($data, $locale = null, array $options = array())
+    public function __construct($data = null, $locale = null, array $options = array())
     {
         if (isset(self::$_cache)) {
             $id = 'Zend_Translate_' . $this->toString() . '_Options';
@@ -123,7 +123,10 @@ abstract class Zend_Translate_Adapter {
         }
 
         $this->setOptions($options);
-        $this->addTranslation($data, $locale, $options);
+        if ($data !== null) {
+            $this->addTranslation($data, $locale, $options);
+        }
+
         if ($this->getLocale() !== (string) $locale) {
             $this->setLocale($locale);
         }

+ 0 - 13
library/Zend/Translate/Adapter/Array.php

@@ -38,19 +38,6 @@ class Zend_Translate_Adapter_Array extends Zend_Translate_Adapter
     private $_data = array();
 
     /**
-     * Generates the adapter
-     *
-     * @param  array               $data     Translation data
-     * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
-     *                                       see Zend_Locale for more information
-     * @param  array               $options  OPTIONAL Options to set
-     */
-    public function __construct($data, $locale = null, array $options = array())
-    {
-        parent::__construct($data, $locale, $options);
-    }
-
-    /**
      * Load translation data
      *
      * @param  string|array  $data

+ 3 - 3
library/Zend/Translate/Adapter/Csv.php

@@ -40,12 +40,12 @@ class Zend_Translate_Adapter_Csv extends Zend_Translate_Adapter
     /**
      * Generates the adapter
      *
-     * @param  string              $data     Translation data
+     * @param  string              $data     OPTIONAL Translation data
      * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
      *                                       see Zend_Locale for more information
-     * @param  array               $options  Options for this adapter
+     * @param  array               $options  OPTIONAL Options for this adapter
      */
-    public function __construct($data, $locale = null, array $options = array())
+    public function __construct($data = null, $locale = null, array $options = array())
     {
         $this->_options['delimiter'] = ";";
         $this->_options['length']    = 0;

+ 0 - 13
library/Zend/Translate/Adapter/Gettext.php

@@ -39,19 +39,6 @@ class Zend_Translate_Adapter_Gettext extends Zend_Translate_Adapter {
     private $_data        = array();
 
     /**
-     * Generates the  adapter
-     *
-     * @param  string              $data     Translation data
-     * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
-     *                                       see Zend_Locale for more information
-     * @param  array               $options  OPTIONAL Options to set
-     */
-    public function __construct($data, $locale = null, array $options = array())
-    {
-        parent::__construct($data, $locale, $options);
-    }
-
-    /**
      * Read values from the MO file
      *
      * @param  string  $bytes

+ 0 - 13
library/Zend/Translate/Adapter/Ini.php

@@ -36,19 +36,6 @@ class Zend_Translate_Adapter_Ini extends Zend_Translate_Adapter
     private $_data = array();
 
     /**
-     * Generates the adapter
-     *
-     * @param  array               $data     Translation data
-     * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
-     *                                       see Zend_Locale for more information
-     * @param  array               $options  OPTIONAL Options to set
-     */
-    public function __construct($data, $locale = null, array $options = array())
-    {
-        parent::__construct($data, $locale, $options);
-    }
-
-    /**
      * Load translation data
      *
      * @param  string|array  $data

+ 0 - 15
library/Zend/Translate/Adapter/Qt.php

@@ -47,21 +47,6 @@ class Zend_Translate_Adapter_Qt extends Zend_Translate_Adapter {
     private $_data        = array();
 
     /**
-     * Generates the Qt adapter
-     * This adapter reads with php's xml_parser
-     *
-     * @param  string              $data     Translation data
-     * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
-     *                                       see Zend_Locale for more information
-     * @param  array               $options  OPTIONAL Options to set
-     */
-    public function __construct($data, $locale = null, array $options = array())
-    {
-        parent::__construct($data, $locale, $options);
-    }
-
-
-    /**
      * Load translation data (QT file reader)
      *
      * @param  string  $locale    Locale/Language to add data for, identical with locale identifier,

+ 0 - 14
library/Zend/Translate/Adapter/Tbx.php

@@ -44,20 +44,6 @@ class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter {
     private $_data        = array();
 
     /**
-     * Generates the tbx adapter
-     * This adapter reads with php's xml_parser
-     *
-     * @param  string              $data     Translation data
-     * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
-     *                                       see Zend_Locale for more information
-     * @param  array               $options  OPTIONAL Options to set
-     */
-    public function __construct($data, $locale = null, array $options = array())
-    {
-        parent::__construct($data, $locale, $options);
-    }
-
-    /**
      * Load translation data (TBX file reader)
      *
      * @param  string  $filename  TBX file to add, full path must be given for access

+ 0 - 15
library/Zend/Translate/Adapter/Tmx.php

@@ -43,21 +43,6 @@ class Zend_Translate_Adapter_Tmx extends Zend_Translate_Adapter {
     private $_data    = array();
 
     /**
-     * Generates the tmx adapter
-     * This adapter reads with php's xml_parser
-     *
-     * @param  string              $data     Translation data
-     * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
-     *                                       see Zend_Locale for more information
-     * @param  array               $options  OPTIONAL Options to set
-     */
-    public function __construct($data, $locale = null, array $options = array())
-    {
-        parent::__construct($data, $locale, $options);
-    }
-
-
-    /**
      * Load translation data (TMX file reader)
      *
      * @param  string  $filename  TMX file to add, full path must be given for access

+ 0 - 15
library/Zend/Translate/Adapter/Xliff.php

@@ -47,21 +47,6 @@ class Zend_Translate_Adapter_Xliff extends Zend_Translate_Adapter {
     private $_data        = array();
 
     /**
-     * Generates the xliff adapter
-     * This adapter reads with php's xml_parser
-     *
-     * @param  string              $data     Translation data
-     * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
-     *                                       see Zend_Locale for more information
-     * @param  array               $options  OPTIONAL Options to set
-     */
-    public function __construct($data, $locale = null, array $options = array())
-    {
-        parent::__construct($data, $locale, $options);
-    }
-
-
-    /**
      * Load translation data (XLIFF file reader)
      *
      * @param  string  $locale    Locale/Language to add data for, identical with locale identifier,

+ 0 - 15
library/Zend/Translate/Adapter/XmlTm.php

@@ -43,21 +43,6 @@ class Zend_Translate_Adapter_XmlTm extends Zend_Translate_Adapter {
     private $_data        = array();
 
     /**
-     * Generates the xmltm adapter
-     * This adapter reads with php's xml_parser
-     *
-     * @param  string              $data     Translation data
-     * @param  string|Zend_Locale  $locale   OPTIONAL Locale/Language to set, identical with locale identifier,
-     *                                       see Zend_Locale for more information
-     * @param  array               $options  OPTIONAL Options to set
-     */
-    public function __construct($data, $locale = null, array $options = array())
-    {
-        parent::__construct($data, $locale, $options);
-    }
-
-
-    /**
      * Load translation data (XMLTM file reader)
      *
      * @param  string  $locale    Locale/Language to add data for, identical with locale identifier,

+ 9 - 0
tests/Zend/TranslateTest.php

@@ -617,6 +617,15 @@ class Zend_TranslateTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * ZF-7941
+     */
+    public function testEmptyTranslation()
+    {
+        $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, null, null, array('disableNotices' => true));
+        $this->assertEquals(0, count($lang->getList()));
+    }
+
+    /**
      * Ignores a raised PHP error when in effect, but throws a flag to indicate an error occurred
      *
      * @param  integer $errno