public function testParsePlural() { $path = CakePlugin::path('Translations') . 'Test/Files/plural.po'; $result = PoParser::parse($path); $expected = array('count' => 3, 'translations' => array(array('locale' => 'en', 'domain' => 'plural', 'category' => 'LC_MESSAGES', 'key' => '%d post', 'value' => '1 post'), array('locale' => 'en', 'domain' => 'plural', 'category' => 'LC_MESSAGES', 'key' => '%d posts', 'value' => '1 post', 'single_key' => '%d post', 'plural_case' => 0), array('locale' => 'en', 'domain' => 'plural', 'category' => 'LC_MESSAGES', 'key' => '%d posts', 'value' => '%d many posts', 'single_key' => '%d post', 'plural_case' => 1)), 'settings' => array('domain' => 'plural')); $this->assertSame($expected, $result); }
/** * Reads and parses a file * * @param string $filepath * @param array $options * @throws \Exception. * @return array. List of entries found in string po formatted */ public static function parseFile($filepath, $options = array()) { $parser = new PoParser(new FileHandler($filepath), $options); $parser->parse(); return $parser; }
public static function parse($file, $defaults = array()) { $return = parent::parse($file, $defaults); $return['settings']['overwrite'] = false; return $return; }
/** * Test update comments */ public function testUpdateComments() { $fileHandler = new FileHandler(__DIR__ . '/pofiles/context.po'); $parser = new PoParser($fileHandler); $entries = $parser->parse(); $options = $parser->getOptions(); $ctxtGlue = $options['context-glue']; $msgid = 'Background Attachment' . $ctxtGlue . 'Attachment'; $entry = $entries[$msgid]; $entry['ccomment'] = array('Test write ccomment'); $entry['tcomment'] = array('Test write tcomment'); $parser->setEntry($msgid, $entry); $parser->writeFile(__DIR__ . '/pofiles/temp.po'); $parser = PoParser::parseFile(__DIR__ . '/pofiles/temp.po'); $entries = $parser->getEntries(); $this->assertEquals($entries[$msgid]['tcomment'][0], $entry['tcomment'][0]); $this->assertEquals($entries[$msgid]['ccomment'][0], $entry['ccomment'][0]); }