* @author Ian Eure * @copyright 2004-2007 Lorenzo Alberton, Ian Eure * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version CVS: $Id$ * @link http://pear.php.net/package/Translation2 */ /** * Load Translation2_Decorator class */ require_once 'Translation2/Admin/Decorator.php'; /** * Automatically add requested strings * * This Decorator will add strings to a language when a request for them to be * translated happens. The 'autoaddlang' option must be set to the language the * strings will be added as. * * Example: *
 * $tr =& Translation2_Admin::factory(...);
 * $tr->setLang('en');
 * $tr =& $tr->getAdminDecorator('Autoadd');
 * $tr->setOption('autoaddlang', 'en');
 * ...
 * $tr->get('Entirely new string', 'samplePage', 'de');
 * 
* * 'Entirely new string' will be added to the English language table. * * @category Internationalization * @package Translation2 * @author Ian Eure * @copyright 2004-2007 Ian Eure * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @link http://pear.php.net/package/Translation2 * @since 2.0.0beta3 */ class Translation2_Admin_Decorator_Autoadd extends Translation2_Admin_Decorator { /** * Language to add strings in * * @var string */ var $autoaddlang = ''; /** * Get a translated string * * @param string $stringID string ID * @param string $pageID page/group ID * @param string $langID language ID * * @return string * @see Translation2::get() */ function get($stringID, $pageID = TRANSLATION2_DEFAULT_PAGEID, $langID = null) { $pageID = ($pageID == TRANSLATION2_DEFAULT_PAGEID ? $this->translation2->currentPageID : $pageID); $string = $this->translation2->get($stringID, $pageID, $langID); if (PEAR::isError($string) || !strlen($string) && !empty($this->autoaddlang) && $langID == $this->autoaddlang) { // Make sure we add a stub for all languages we know about. $langs = array(); foreach ($this->translation2->getLangs('ids') as $lang) { $langs[$lang] = ''; } $langs[$this->autoaddlang] = $stringID; // Add the string $this->translation2->add($stringID, $pageID, $langs); } return $string; } } ?>