public function testHashing() { $item1 = array('id' => 'a', 'str' => 'b', 'ctxt' => false); $item2 = array('id' => 'a', 'str' => 'b', 'ctxt' => ''); $this->assertNotEquals(GettextFFS::generateKeyFromItem($item1, 'legacy'), GettextFFS::generateKeyFromItem($item2, 'legacy'), 'Empty msgctxt is different from no msgctxt'); $this->assertNotEquals(GettextFFS::generateKeyFromItem($item1, 'simple'), GettextFFS::generateKeyFromItem($item2, 'simple'), 'Empty msgctxt is different from no msgctxt'); $this->assertEquals(sha1($item1['id']) . '-' . $item1['id'], GettextFFS::generateKeyFromItem($item1, 'legacy')); $this->assertEquals(substr(sha1($item1['id']), 0, 6) . '-' . $item1['id'], GettextFFS::generateKeyFromItem($item1, 'simple')); }
/** * Try parsing file. * @param $data * @return array */ protected function parseFile($data) { /** Construct a dummy group for us... * @todo Time to rethink the interface again? */ $group = MessageGroupBase::factory(array('FILES' => array('class' => 'GettextFFS', 'CtxtAsKey' => true), 'BASIC' => array('class' => 'FileBasedMessageGroup', 'namespace' => -1))); $ffs = new GettextFFS($group); $data = $ffs->readFromVariable($data); /** * Special data added by GettextFFS */ $metadata = $data['METADATA']; /** * This should catch everything that is not a gettext file exported from us */ if (!isset($metadata['code']) || !isset($metadata['group'])) { return array('no-headers'); } /** * And check for stupid editors that drop msgctxt which * unfortunately breaks submission. */ if (isset($metadata['warnings'])) { global $wgLang; return array('warnings', $wgLang->commaList($metadata['warnings'])); } return array('ok', $data); }
public function output() { if (MessageGroups::isDynamic($this->group)) { return 'Not supported'; } $ffs = null; if ($this->group instanceof FileBasedMessageGroup) { $ffs = $this->group->getFFS(); } if (!$ffs instanceof GettextFFS) { $group = FileBasedMessageGroup::newFromMessageGroup($this->group); $ffs = new GettextFFS($group); } $ffs->setOfflineMode('true'); $code = $this->options['language']; $id = $this->group->getID(); $filename = "{$id}_{$code}.po"; header("Content-Disposition: attachment; filename=\"{$filename}\""); return $ffs->writeIntoVariable($this->collection); }