From 903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Thu, 12 Jul 2012 11:21:01 +0000 Subject: standardize the use of unix eol; use svn properties to enforce native eol --- framework/I18N/core/Gettext/PO.php | 320 ++++++++++++++++++------------------- 1 file changed, 160 insertions(+), 160 deletions(-) (limited to 'framework/I18N/core/Gettext/PO.php') diff --git a/framework/I18N/core/Gettext/PO.php b/framework/I18N/core/Gettext/PO.php index 54fe10e3..57028f6d 100644 --- a/framework/I18N/core/Gettext/PO.php +++ b/framework/I18N/core/Gettext/PO.php @@ -1,160 +1,160 @@ - - * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $ - * @package System.I18N.core - */ - -// +----------------------------------------------------------------------+ -// | PEAR :: File :: Gettext :: PO | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is available at http://www.php.net/license/3_0.txt | -// | If you did not receive a copy of the PHP license and are unable | -// | to obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Copyright (c) 2004 Michael Wallner | -// +----------------------------------------------------------------------+ -// -// $Id$ - -/** - * File::Gettext::PO - * - * @author Michael Wallner - * @license PHP License - */ - -require_once dirname(__FILE__).'/TGettext.php'; - -/** - * File_Gettext_PO - * - * GNU PO file reader and writer. - * - * @author Michael Wallner - * @version $Revision: 1.2 $ - * @access public - * @package System.I18N.core - */ -class TGettext_PO extends TGettext -{ - /** - * Constructor - * - * @access public - * @return object File_Gettext_PO - * @param string path to GNU PO file - */ - function TGettext_PO($file = '') - { - $this->file = $file; - } - - /** - * Load PO file - * - * @access public - * @return mixed Returns true on success or PEAR_Error on failure. - * @param string $file - */ - function load($file = null) - { - if (!isset($file)) { - $file = $this->file; - } - - // load file - if (!$contents = @file($file)) { - return false; - } - $contents = implode('', $contents); - - // match all msgid/msgstr entries - $matched = preg_match_all( - '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' . - '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/', - $contents, $matches - ); - unset($contents); - - if (!$matched) { - return false; - } - - // get all msgids and msgtrs - for ($i = 0; $i < $matched; $i++) { - $msgid = preg_replace( - '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]); - $msgstr= preg_replace( - '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); - $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); - } - - // check for meta info - if (isset($this->strings[''])) { - $this->meta = parent::meta2array($this->strings['']); - unset($this->strings['']); - } - - return true; - } - - /** - * Save PO file - * - * @access public - * @return mixed Returns true on success or PEAR_Error on failure. - * @param string $file - */ - function save($file = null) - { - if (!isset($file)) { - $file = $this->file; - } - - // open PO file - if (!is_resource($fh = @fopen($file, 'w'))) { - return false; - } - - // lock PO file exclusively - if (!flock($fh, LOCK_EX)) { - fclose($fh); - return false; - } - // write meta info - if (count($this->meta)) { - $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n"; - foreach ($this->meta as $k => $v) { - $meta .= '"' . $k . ': ' . $v . '\n"' . "\n"; - } - fwrite($fh, $meta . "\n"); - } - // write strings - foreach ($this->strings as $o => $t) { - fwrite($fh, - 'msgid "' . parent::prepare($o, true) . '"' . "\n" . - 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" - ); - } - - //done - @flock($fh, LOCK_UN); - @fclose($fh); - chmod($file,PRADO_CHMOD); - return true; - } -} + + * @version $Revision: 1.2 $ $Date: 2005/01/05 03:15:14 $ + * @package System.I18N.core + */ + +// +----------------------------------------------------------------------+ +// | PEAR :: File :: Gettext :: PO | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 3.0 of the PHP license, | +// | that is available at http://www.php.net/license/3_0.txt | +// | If you did not receive a copy of the PHP license and are unable | +// | to obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Copyright (c) 2004 Michael Wallner | +// +----------------------------------------------------------------------+ +// +// $Id$ + +/** + * File::Gettext::PO + * + * @author Michael Wallner + * @license PHP License + */ + +require_once dirname(__FILE__).'/TGettext.php'; + +/** + * File_Gettext_PO + * + * GNU PO file reader and writer. + * + * @author Michael Wallner + * @version $Revision: 1.2 $ + * @access public + * @package System.I18N.core + */ +class TGettext_PO extends TGettext +{ + /** + * Constructor + * + * @access public + * @return object File_Gettext_PO + * @param string path to GNU PO file + */ + function TGettext_PO($file = '') + { + $this->file = $file; + } + + /** + * Load PO file + * + * @access public + * @return mixed Returns true on success or PEAR_Error on failure. + * @param string $file + */ + function load($file = null) + { + if (!isset($file)) { + $file = $this->file; + } + + // load file + if (!$contents = @file($file)) { + return false; + } + $contents = implode('', $contents); + + // match all msgid/msgstr entries + $matched = preg_match_all( + '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' . + '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/', + $contents, $matches + ); + unset($contents); + + if (!$matched) { + return false; + } + + // get all msgids and msgtrs + for ($i = 0; $i < $matched; $i++) { + $msgid = preg_replace( + '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]); + $msgstr= preg_replace( + '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); + $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); + } + + // check for meta info + if (isset($this->strings[''])) { + $this->meta = parent::meta2array($this->strings['']); + unset($this->strings['']); + } + + return true; + } + + /** + * Save PO file + * + * @access public + * @return mixed Returns true on success or PEAR_Error on failure. + * @param string $file + */ + function save($file = null) + { + if (!isset($file)) { + $file = $this->file; + } + + // open PO file + if (!is_resource($fh = @fopen($file, 'w'))) { + return false; + } + + // lock PO file exclusively + if (!flock($fh, LOCK_EX)) { + fclose($fh); + return false; + } + // write meta info + if (count($this->meta)) { + $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n"; + foreach ($this->meta as $k => $v) { + $meta .= '"' . $k . ': ' . $v . '\n"' . "\n"; + } + fwrite($fh, $meta . "\n"); + } + // write strings + foreach ($this->strings as $o => $t) { + fwrite($fh, + 'msgid "' . parent::prepare($o, true) . '"' . "\n" . + 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" + ); + } + + //done + @flock($fh, LOCK_UN); + @fclose($fh); + chmod($file,PRADO_CHMOD); + return true; + } +} -- cgit v1.2.3