示例#1
0
 /**
  * Creates a MessageFormat with the given pattern and uses it to format
  * the given substitutes.
  *
  * This static method is shortcut of:
  * <code>
  * (new MessageFormat($pattern)).format($substitutes)
  * </code>
  *
  * @param
  *            string
  * @param
  *            Array()
  * @return string
  */
 public static function formatString($pattern, $substitutes = array())
 {
     $msgFormat = new MessageFormat($pattern);
     return $msgFormat->format($substitutes);
 }
 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);
 }
 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!');
 }