/** * 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 (TPropertyValue::ensureBoolean($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; } } }
/** * Get the list of messages for a particular catalogue. * @param TEventParameter event parameter. */ function onLoad($param) { $settings = $this->Module->getSettings(); $source = MessageSource::factory($settings['type'], $settings['source']); $source->setCulture($settings['culture']); $source->load($settings['catalogue']); $messages = $source->read(); $messages = $messages[key($messages)]; $this->MessageList->setDataSource($messages); $this->dataBind(); parent::onLoad($param); }
function testAltCatalogue() { $source = MessageSource::factory($this->type, $this->source); $source->setCulture('en_AU'); $source->setCache(new MessageCache('./tmp')); $formatter = new MessageFormat($source); $formatter->Catalogue = 'tests'; //from a different catalogue $this->assertEqual($formatter->format('Hello'), 'Howdy!'); $this->assertEqual($formatter->format('Welcome'), 'Ho Ho!'); $this->assertEqual($formatter->format('Goodbye'), 'Sayonara'); //switch to 'messages' catalogue $this->assertEqual($formatter->format('Hello', null, 'messages'), 'G\'day Mate!'); }
/** * Initialize the TTranslate translation components */ public static function init() { //initialized the default class wide formatter if (is_null(self::$formatter)) { $app = pradoGetApplication()->getGlobalization(); //var_dump($app); $source = MessageSource::factory($app->Translation['type'], $app->Translation['source'], $app->Translation['filename']); $source->setCulture($app->Culture); if ($app->Cache) { $source->setCache(new MessageCache($app->Cache)); } self::$formatter = new MessageFormat($source, $app->Charset); } }
function testDirectoryTypeSaveUpdateDelete() { $MObackup = './messages/en_AU/tests.mo.bak'; $MOfile = './messages/en_AU/tests.mo'; $PObackup = './messages/en_AU/tests.po.bak'; $POfile = './messages/en_AU/tests.po'; //restore using the back file copy($MObackup, $MOfile); copy($PObackup, $POfile); //test that the back file doesn't contain the 'Testing123' string. $this->assertNoUnwantedPattern('/Testing123/', file_get_contents($MOfile)); $this->assertNoUnwantedPattern('/Testing123/', file_get_contents($POfile)); $source = MessageSource::factory($this->type, $this->source); $source->setCulture('en_AU'); $source->setCache(new MessageCache('./tmp')); $formatter = new MessageFormat($source); //add a untranslated string, note, doesn't matter which catalogue $this->assertEqual($formatter->format('Testing123'), 'Testing123'); //save it to the 'tests' catalgoue $this->assertTrue($formatter->getSource()->save('tests')); //check the contents //$this->assertWantedPattern('/Testing123/',file_get_contents($MOfile)); $this->assertWantedPattern('/Testing123/', file_get_contents($POfile)); //testing for update. Update it to the 'tests' catalogue $this->assertTrue($formatter->getSource()->update('Testing123', '123Test', 'update comments', 'tests')); $this->assertWantedPattern('/123Test/', file_get_contents($MOfile)); //now doing some delete from the 'tests' catalogue $this->assertFalse($formatter->getSource()->delete('Test123', 'tests')); $this->assertTrue($formatter->getSource()->delete('Testing123', 'tests')); $this->assertNoUnwantedPattern('/Testing123/', file_get_contents($MOfile)); $this->assertNoUnwantedPattern('/Testing123/', file_get_contents($POfile)); //restore using the backup file. copy($MObackup, $MOfile); copy($PObackup, $POfile); }
/** * Update a message translation. * @param string the message id/source * @param string the translated message * @param string comments * @param array translation settings. * @return true if translation was updated, false otherwise. */ function updateMessage($text, $target, $comments, $settings) { $source = MessageSource::factory($settings['type'], $settings['source']); $app = $this->Application->getGlobalization(); if ($app->Cache) { $source->setCache(new MessageCache($app->Cache)); } $source->setCulture($settings['culture']); return $source->update($text, $target, $comments, $settings['catalogue']); }