Prado\I18N\Translation::init PHP Метод

init() публичный статический Метод

Initialize the TTranslate translation components
public static init ( $catalogue = 'messages' )
    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;
            }
        }
    }

Usage Example

Пример #1
0
 /**
  * Translates the text with subsititution.
  * @param string text for translation
  * @param array list of substitutions
  * @return string translated text
  */
 protected function translateText($text, $subs)
 {
     $app = $this->getApplication()->getGlobalization();
     //no translation handler provided
     if (($config = $app->getTranslationConfiguration()) === null) {
         return strtr($text, $subs);
     }
     $catalogue = $this->getCatalogue();
     if (empty($catalogue) && isset($config['catalogue'])) {
         $catalogue = $config['catalogue'];
     }
     if (empty($catalogue)) {
         $catalogue = 'messages';
     }
     Translation::init($catalogue);
     $key = $this->getKey();
     if (!empty($key)) {
         $text = $key;
     }
     //translate it
     return Translation::formatter($catalogue)->format($text, $subs, $catalogue, $this->getCharset());
 }
All Usage Examples Of Prado\I18N\Translation::init