framework/i18n/gettext/CGettextMoFile.php
public function save($file,$messages)
	{
		if(!($fw=@fopen($file,'wb')))
			throw new CException(Yii::t('yii','Unable to write file "{file}".',
				array('{file}'=>$file)));

		if(!@flock($fw,LOCK_EX))
			throw new CException(Yii::t('yii','Unable to lock file "{file}" for writing.',
				array('{file}'=>$file)));

		// magic
		if($this->useBigEndian)
			$this->writeByte($fw,pack('c*', 0x95, 0x04, 0x12, 0xde));
		else
			$this->writeByte($fw,pack('c*', 0xde, 0x12, 0x04, 0x95));

		// revision
		$this->writeInteger($fw,0);

		// message count
		$n=count($messages);
		$this->writeInteger($fw,$n);

		// offset of source message table
		$offset=28;
		$this->writeInteger($fw,$offset);
		$offset+=($n*8);
		$this->writeInteger($fw,$offset);
		// hashtable size, omitted
		$this->writeInteger($fw,0);
		$offset+=($n*8);
		$this->writeInteger($fw,$offset);

		// length and offsets for source messagess
		foreach(array_keys($messages) as $id)
		{
			$len=strlen($id);
			$this->writeInteger($fw,$len);
			$this->writeInteger($fw,$offset);
			$offset+=$len+1;
		}

		// length and offsets for target messagess
		foreach($messages as $message)
		{
			$len=strlen($message);
			$this->writeInteger($fw,$len);
			$this->writeInteger($fw,$offset);
			$offset+=$len+1;
		}

		// source messages
		foreach(array_keys($messages) as $id)
			$this->writeString($fw,$id);

		// target messages
		foreach($messages as $message)
			$this->writeString($fw,$message);

		@flock($fw,LOCK_UN);
		@fclose($fw);
	}
public function save($file,$messages)
	{
		if(!($fw=@fopen($file,'wb')))
			throw new CException(Yii::t('yii','Unable to write file "{file}".',
				array('{file}'=>$file)));

		if(!@flock($fw,LOCK_EX))
			throw new CException(Yii::t('yii','Unable to lock file "{file}" for writing.',
				array('{file}'=>$file)));

		// magic
		if($this->useBigEndian)
			$this->writeByte($fw,pack('c*', 0x95, 0x04, 0x12, 0xde));
		else
			$this->writeByte($fw,pack('c*', 0xde, 0x12, 0x04, 0x95));

		// revision
		$this->writeInteger($fw,0);

		// message count
		$n=count($messages);
		$this->writeInteger($fw,$n);

		// offset of source message table
		$offset=28;
		$this->writeInteger($fw,$offset);
		$offset+=($n*8);
		$this->writeInteger($fw,$offset);
		// hashtable size, omitted
		$this->writeInteger($fw,0);
		$offset+=($n*8);
		$this->writeInteger($fw,$offset);

		// length and offsets for source messagess
		foreach(array_keys($messages) as $id)
		{
			$len=strlen($id);
			$this->writeInteger($fw,$len);
			$this->writeInteger($fw,$offset);
			$offset+=$len+1;
		}

		// length and offsets for target messagess
		foreach($messages as $message)
		{
			$len=strlen($message);
			$this->writeInteger($fw,$len);
			$this->writeInteger($fw,$offset);
			$offset+=$len+1;
		}

		// source messages
		foreach(array_keys($messages) as $id)
			$this->writeString($fw,$id);

		// target messages
		foreach($messages as $message)
			$this->writeString($fw,$message);

		@flock($fw,LOCK_UN);
		@fclose($fw);
	}
public function save ( $ file , $ messages ) { if ( ! ( $ fw = @ fopen ( $ file , 'wb' ) ) ) throw new CException ( Yii :: t ( 'yii' , 'Unable to write file "{file}".' , array ( '{file}' => $ file ) ) ) ; if ( ! @ flock ( $ fw , LOCK_EX ) ) throw new CException ( Yii :: t ( 'yii' , 'Unable to lock file "{file}" for writing.' , array ( '{file}' => $ file ) ) ) ; // magic if ( $ this -> useBigEndian ) $ this -> writeByte ( $ fw , pack ( 'c*' , 0x95 , 0x04 , 0x12 , 0xde ) ) ; else $ this -> writeByte ( $ fw , pack ( 'c*' , 0xde , 0x12 , 0x04 , 0x95 ) ) ; // revision $ this -> writeInteger ( $ fw , 0 ) ; // message count $ n = count ( $ messages ) ; $ this -> writeInteger ( $ fw , $ n ) ; // offset of source message table $ offset = 28 ; $ this -> writeInteger ( $ fw , $ offset ) ; $ offset += ( $ n * 8 ) ; $ this -> writeInteger ( $ fw , $ offset ) ; // hashtable size, omitted $ this -> writeInteger ( $ fw , 0 ) ; $ offset += ( $ n * 8 ) ; $ this -> writeInteger ( $ fw , $ offset ) ; // length and offsets for source messagess foreach ( array_keys ( $ messages ) as $ id ) { $ len = strlen ( $ id ) ; $ this -> writeInteger ( $ fw , $ len ) ; $ this -> writeInteger ( $ fw , $ offset ) ; $ offset += $ len + 1 ; } // length and offsets for target messagess foreach ( $ messages as $ message ) { $ len = strlen ( $ message ) ; $ this -> writeInteger ( $ fw , $ len ) ; $ this -> writeInteger ( $ fw , $ offset ) ; $ offset += $ len + 1 ; } // source messages foreach ( array_keys ( $ messages ) as $ id ) $ this -> writeString ( $ fw , $ id ) ; // target messages foreach ( $ messages as $ message ) $ this -> writeString ( $ fw , $ message ) ; @ flock ( $ fw , LOCK_UN ) ; @ fclose ( $ fw ) ; }
Saves messages to an MO file.
@param string $file file path
@param array $messages message translations (message id => translated message).
Note if the message has a context, the message id must be prefixed with
the context with chr(4) as the separator.
@throws CException
Saves messages to an MO file .