Translation2
[ class tree: Translation2 ] [ index: Translation2 ] [ all elements ]

Source for file Autoadd.php

Documentation is available at Autoadd.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2004 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Lorenzo Alberton <l dot alberton at quipo dot it>           |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Autoadd.php,v 1.2 2004/10/28 11:20:43 quipo Exp $
  20.  
  21. require_once 'Translation2/Admin/Decorator.php';
  22.  
  23. /**
  24.  * Automatically add requested strings
  25.  *
  26.  * This Decorator will add strings to a language when a request for them to be
  27.  * translated happens. The 'autoaddlang' option must be set to the language the
  28.  * strings will be added as.
  29.  *
  30.  * Example:
  31.  *
  32.  * $tr =& Translation2_Admin::factory(...);
  33.  * $tr->setLang('en');
  34.  * $tr =& $tr->getAdminDecorator('Autoadd');
  35.  * $tr->setOption('autoaddlang', 'en');
  36.  * ...
  37.  * $tr->get('Entirely new string', 'samplePage', 'de');
  38.  *
  39.  * 'Entirely new string' will be added to the English language table.
  40.  *
  41.  * @package Translation2
  42.  * @version @version@
  43.  * @author Ian Eure <ieure>
  44.  * @since 2.0.0beta3
  45.  */
  46.  
  47.     /**
  48.      * Language to add strings in
  49.      *
  50.      * @var  string 
  51.      */
  52.     var $autoaddlang = '';
  53.  
  54.     /**
  55.      * Get a translated string
  56.      *
  57.      * @see   Translation2::get()
  58.      */
  59.     function get($stringID$pageID = TRANSLATION2_DEFAULT_PAGEID$langID = null)
  60.     {
  61.         $pageID ($pageID == TRANSLATION2_DEFAULT_PAGEID ? $this->translation2->currentPageID : $pageID);
  62.         $string $this->translation2->get($stringID$pageID$langID);
  63.         if (PEAR::isError($string|| empty($string&&
  64.             !empty($this->autoaddlang)) {
  65.             // Add the string
  66.             $this->translation2->add($stringID$pageIDarray(
  67.                 $this->autoaddlang => $stringID
  68.             ));
  69.         }
  70.         return $string;
  71.     }
  72. }
  73.  
  74. ?>

Documentation generated on Mon, 11 Mar 2019 13:58:51 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.