The base class for all MessageSources. Message sources must be instantiated using the factory method. The default valid sources are # XLIFF -- using XML XLIFF format to store the translation messages. # gettext -- Translated messages are stored in the gettext format. # Database -- Use an existing TDbConnection to store the messages. # SQLite -- (Deprecated) Store the translation messages in a SQLite database. A custom message source can be instantiated by specifying the filename parameter to point to the custom class file. E.g. $resource = '...'; //custom message source resource $classfile = '../MessageSource_MySource.php'; //custom message source $source = MessageSource::factory('MySource', $resource, $classfile); If you are writting your own message sources, pay attention to the loadCatalogue method. It details how the resources are loaded and cached. See also the existing message source types as examples. The following example instantiates a Database message source, set the culture, set the cache handler, and use the source in a message formatter. The messages are stored using an existing connection. The source parameter for the factory method must contain a valid ConnectionID. db1 must be already configured $source = MessageSource::factory('Database', 'db1'); set the culture and cache, store the cache in the /tmp directory. $source->setCulture('en_AU')l $source->setCache(new MessageCache('/tmp')); $formatter = new MessageFormat($source);
Наследование: implements Prado\I18N\core\IMessageSource
Пример #1
0
 /**
  * Initialize the TTranslate translation components
  */
 public static function init($catalogue = 'messages')
 {
     static $saveEventHandlerAttached = false;
     //initialized the default class wide formatter
     if (!isset(self::$formatters[$catalogue])) {
         $app = Prado::getApplication()->getGlobalization();
         $config = $app->getTranslationConfiguration();
         $source = MessageSource::factory($config['type'], $config['source'], $config['filename']);
         $source->setCulture($app->getCulture());
         if (isset($config['cache'])) {
             $source->setCache(new MessageCache($config['cache']));
         }
         self::$formatters[$catalogue] = new MessageFormat($source, $app->getCharset());
         //mark untranslated text
         if ($ps = $config['marker']) {
             self::$formatters[$catalogue]->setUntranslatedPS(array($ps, $ps));
         }
         //save the message on end request
         // Do it only once !
         if (!$saveEventHandlerAttached && TPropertyValue::ensureBoolean($config['autosave'])) {
             Prado::getApplication()->attachEventHandler('OnEndRequest', array('Translation', 'saveMessages'));
             $saveEventHandlerAttached = true;
         }
     }
 }