[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * Translation, static. 4 * 5 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: Translation.php 1441 2006-09-23 07:30:43Z wei $ 10 * @package System.I18N 11 */ 12 13 /** 14 * Get the MessageFormat class. 15 */ 16 Prado::using('System.I18N.core.MessageFormat'); 17 18 19 /** 20 * Translation class. 21 * 22 * Provides translation using a static MessageFormatter. 23 * 24 * @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com> 25 * @version v1.0, last update on Tue Dec 28 11:54:48 EST 2004 26 * @package System.I18N 27 */ 28 class Translation extends TComponent 29 { 30 /** 31 * The string formatter. This is a class static variable. 32 * @var MessageFormat 33 */ 34 protected static $formatter; 35 36 /** 37 * Initialize the TTranslate translation components 38 */ 39 public static function init() 40 { 41 //initialized the default class wide formatter 42 if(is_null(self::$formatter)) 43 { 44 $app = Prado::getApplication()->getGlobalization(); 45 $config = $app->getTranslationConfiguration(); 46 $source = MessageSource::factory($config['type'], 47 $config['source'], 48 $config['filename']); 49 50 $source->setCulture($app->getCulture()); 51 52 if($config['cache']) 53 $source->setCache(new MessageCache($config['cache'])); 54 55 self::$formatter = new MessageFormat($source, $app->getCharset()); 56 57 //mark untranslated text 58 if($ps=$config['marker']) 59 self::$formatter->setUntranslatedPS(array($ps,$ps)); 60 61 //save the message on end request 62 Prado::getApplication()->attachEventHandler( 63 'OnEndRequest', array('Translation', 'saveMessages')); 64 } 65 } 66 67 /** 68 * Get the static formatter from this component. 69 * @return MessageFormat formattter. 70 * @see localize() 71 */ 72 public static function formatter() 73 { 74 return self::$formatter; 75 } 76 77 /** 78 * Save untranslated messages to the catalogue. 79 */ 80 public static function saveMessages() 81 { 82 static $onceonly = true; 83 84 if($onceonly && !is_null($formatter = self::$formatter)) 85 { 86 $app = Prado::getApplication()->getGlobalization(); 87 $config = $app->getTranslationConfiguration(); 88 if(isset($config['autosave'])) 89 { 90 $formatter->getSource()->setCulture($app->getCulture()); 91 $formatter->getSource()->save($config['catalogue']); 92 } 93 $onceonly = false; 94 } 95 } 96 } 97 98 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |