summaryrefslogtreecommitdiff
path: root/framework/I18N
diff options
context:
space:
mode:
authorxue <>2007-01-17 22:26:53 +0000
committerxue <>2007-01-17 22:26:53 +0000
commitcd236d693d1df3e20c370c97a98c51ba3fcbd610 (patch)
tree4b84a25cc06db000420b75f2ce1f390246869662 /framework/I18N
parent74acb5d2a4426cb4ae7f0fdd86e23c1459813a60 (diff)
Added PRADO_CHMOD constant so that users can specify the permission of PRADO-created directories
Diffstat (limited to 'framework/I18N')
-rw-r--r--framework/I18N/TGlobalization.php4
-rw-r--r--framework/I18N/core/Gettext/MO.php88
-rw-r--r--framework/I18N/core/Gettext/PO.php28
-rw-r--r--framework/I18N/core/MessageSource_XLIFF.php6
-rw-r--r--framework/I18N/core/MessageSource_gettext.php4
5 files changed, 65 insertions, 65 deletions
diff --git a/framework/I18N/TGlobalization.php b/framework/I18N/TGlobalization.php
index 90fd3d53..c2a4f5ed 100644
--- a/framework/I18N/TGlobalization.php
+++ b/framework/I18N/TGlobalization.php
@@ -177,7 +177,7 @@ class TGlobalization extends TModule
if(@mkdir($config['source'])===false)
throw new TConfigurationException('globalization_source_path_failed',
$config['source']);
- chmod($config['source'], 0777); //make it deletable
+ chmod($config['source'], PRADO_CHMOD); //make it deletable
}
}
else
@@ -193,7 +193,7 @@ class TGlobalization extends TModule
if(@mkdir($config['cache'])===false)
throw new TConfigurationException('globalization_cache_path_failed',
$config['cache']);
- chmod($config['cache'], 0777); //make it deletable
+ chmod($config['cache'], PRADO_CHMOD); //make it deletable
}
}
$this->_translation = $config;
diff --git a/framework/I18N/core/Gettext/MO.php b/framework/I18N/core/Gettext/MO.php
index b4899949..9e7460a5 100644
--- a/framework/I18N/core/Gettext/MO.php
+++ b/framework/I18N/core/Gettext/MO.php
@@ -16,7 +16,7 @@
* @package System.I18N.core
*/
-
+
// +----------------------------------------------------------------------+
// | PEAR :: File :: Gettext :: MO |
// +----------------------------------------------------------------------+
@@ -33,43 +33,43 @@
/**
* File::Gettext::MO
- *
+ *
* @author Michael Wallner <mike@php.net>
* @license PHP License
*/
require_once dirname(__FILE__).'/TGettext.php';
-/**
+/**
* File_Gettext_MO
- *
+ *
* GNU MO file reader and writer.
*
* @author Michael Wallner <mike@php.net>
* @version $Revision: 1.3 $
* @access public
- * @package System.I18N.core
+ * @package System.I18N.core
*/
class TGettext_MO extends TGettext
{
/**
* file handle
- *
+ *
* @access private
* @var resource
*/
protected $_handle = null;
-
+
/**
* big endianess
- *
+ *
* Whether to write with big endian byte order.
- *
+ *
* @access public
* @var bool
*/
protected $writeBigEndian = false;
-
+
/**
* Constructor
*
@@ -96,7 +96,7 @@ class TGettext_MO extends TGettext
}
return null;
}
-
+
/**
* _readInt
*
@@ -110,7 +110,7 @@ class TGettext_MO extends TGettext
$unpacked = unpack($bigendian ? 'N' : 'V', $this->_read(4));
return array_shift($unpacked);
}
-
+
/**
* _writeInt
*
@@ -122,7 +122,7 @@ class TGettext_MO extends TGettext
{
return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int));
}
-
+
/**
* _write
*
@@ -134,7 +134,7 @@ class TGettext_MO extends TGettext
{
return fwrite($this->_handle, $data);
}
-
+
/**
* _writeStr
*
@@ -146,13 +146,13 @@ class TGettext_MO extends TGettext
{
return $this->_write($string . "\0");
}
-
+
/**
* _readStr
*
* @access private
* @return string
- * @param array $params associative array with offset and length
+ * @param array $params associative array with offset and length
* of the string
*/
function _readStr($params)
@@ -160,7 +160,7 @@ class TGettext_MO extends TGettext
fseek($this->_handle, $params['offset']);
return $this->_read($params['length']);
}
-
+
/**
* Load MO file
*
@@ -173,7 +173,7 @@ class TGettext_MO extends TGettext
if (!isset($file)) {
$file = $this->file;
}
-
+
// open MO file
if (!is_resource($this->_handle = @fopen($file, 'rb'))) {
return false;
@@ -183,7 +183,7 @@ class TGettext_MO extends TGettext
@fclose($this->_handle);
return false;
}
-
+
// read (part of) magic number from MO file header and define endianess
//unpack returns a reference????
@@ -193,11 +193,11 @@ class TGettext_MO extends TGettext
case -34:
$be = false;
break;
-
+
case -107:
$be = true;
break;
-
+
default:
return false;
}
@@ -206,15 +206,15 @@ class TGettext_MO extends TGettext
if (0 !== ($_rev = $this->_readInt($be))) {
return false;
}
-
+
// count of strings in this file
$count = $this->_readInt($be);
-
+
// offset of hashing table of the msgids
$offset_original = $this->_readInt($be);
// offset of hashing table of the msgstrs
$offset_translat = $this->_readInt($be);
-
+
// move to msgid hash table
fseek($this->_handle, $offset_original);
// read lengths and offsets of msgids
@@ -225,7 +225,7 @@ class TGettext_MO extends TGettext
'offset' => $this->_readInt($be)
);
}
-
+
// move to msgstr hash table
fseek($this->_handle, $offset_translat);
// read lengths and offsets of msgstrs
@@ -236,27 +236,27 @@ class TGettext_MO extends TGettext
'offset' => $this->_readInt($be)
);
}
-
+
// read all
for ($i = 0; $i < $count; $i++) {
- $this->strings[$this->_readStr($original[$i])] =
+ $this->strings[$this->_readStr($original[$i])] =
$this->_readStr($translat[$i]);
}
-
+
// done
@flock($this->_handle, LOCK_UN);
@fclose($this->_handle);
$this->_handle = null;
-
+
// check for meta info
if (isset($this->strings[''])) {
$this->meta = parent::meta2array($this->strings['']);
unset($this->strings['']);
}
-
+
return true;
}
-
+
/**
* Save MO file
*
@@ -269,7 +269,7 @@ class TGettext_MO extends TGettext
if (!isset($file)) {
$file = $this->file;
}
-
+
// open MO file
if (!is_resource($this->_handle = @fopen($file, 'wb'))) {
return false;
@@ -279,36 +279,36 @@ class TGettext_MO extends TGettext
@fclose($this->_handle);
return false;
}
-
+
// write magic number
if ($this->writeBigEndian) {
$this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde));
} else {
$this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95));
}
-
+
// write file format revision
$this->_writeInt(0);
-
+
$count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0));
// write count of strings
$this->_writeInt($count);
-
+
$offset = 28;
// write offset of orig. strings hash table
$this->_writeInt($offset);
-
+
$offset += ($count * 8);
// write offset transl. strings hash table
$this->_writeInt($offset);
-
+
// write size of hash table (we currently ommit the hash table)
$this->_writeInt(0);
-
+
$offset += ($count * 8);
// write offset of hash table
$this->_writeInt($offset);
-
+
// unshift meta info
if ($this->meta) {
$meta = '';
@@ -319,7 +319,7 @@ class TGettext_MO extends TGettext
} else {
$strings = $this->strings;
}
-
+
// write offsets for original strings
foreach (array_keys($strings) as $o) {
$len = strlen($o);
@@ -327,7 +327,7 @@ class TGettext_MO extends TGettext
$this->_writeInt($offset);
$offset += $len + 1;
}
-
+
// write offsets for translated strings
foreach ($strings as $t) {
$len = strlen($t);
@@ -345,11 +345,11 @@ class TGettext_MO extends TGettext
foreach ($strings as $t) {
$this->_writeStr($t);
}
-
+
// done
@flock($this->_handle, LOCK_UN);
@fclose($this->_handle);
- chmod($file,0777);
+ chmod($file,PRADO_CHMOD);
return true;
}
}
diff --git a/framework/I18N/core/Gettext/PO.php b/framework/I18N/core/Gettext/PO.php
index 7df99496..66c4596f 100644
--- a/framework/I18N/core/Gettext/PO.php
+++ b/framework/I18N/core/Gettext/PO.php
@@ -32,22 +32,22 @@
/**
* File::Gettext::PO
- *
+ *
* @author Michael Wallner <mike@php.net>
* @license PHP License
*/
-
+
require_once dirname(__FILE__).'/TGettext.php';
-/**
+/**
* File_Gettext_PO
*
* GNU PO file reader and writer.
- *
+ *
* @author Michael Wallner <mike@php.net>
* @version $Revision: 1.2 $
* @access public
- * @package System.I18N.core
+ * @package System.I18N.core
*/
class TGettext_PO extends TGettext
{
@@ -75,13 +75,13 @@ class TGettext_PO extends TGettext
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+' .
@@ -89,11 +89,11 @@ class TGettext_PO extends TGettext
$contents, $matches
);
unset($contents);
-
+
if (!$matched) {
return false;
}
-
+
// get all msgids and msgtrs
for ($i = 0; $i < $matched; $i++) {
$msgid = preg_replace(
@@ -102,16 +102,16 @@ class TGettext_PO extends TGettext
'/\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
*
@@ -150,11 +150,11 @@ class TGettext_PO extends TGettext
'msgstr "' . parent::prepare($t, true) . '"' . "\n\n"
);
}
-
+
//done
@flock($fh, LOCK_UN);
@fclose($fh);
- chmod($file,0777);
+ chmod($file,PRADO_CHMOD);
return true;
}
}
diff --git a/framework/I18N/core/MessageSource_XLIFF.php b/framework/I18N/core/MessageSource_XLIFF.php
index 1f537932..eafc0983 100644
--- a/framework/I18N/core/MessageSource_XLIFF.php
+++ b/framework/I18N/core/MessageSource_XLIFF.php
@@ -478,15 +478,15 @@ class MessageSource_XLIFF extends MessageSource
$variant = array_shift($variants);
$file = $this->getSource($variant);
$dir = dirname($file);
- if(!is_dir($dir))
+ if(!is_dir($dir))
{
@mkdir($dir);
- @chmod($dir,0777);
+ @chmod($dir,PRADO_CHMOD);
}
if(!is_dir($dir))
throw new TException("Unable to create directory $dir");
file_put_contents($file, $this->getTemplate($catalogue));
- chmod($file, 0777);
+ chmod($file, PRADO_CHMOD);
return array($variant, $file);
}
diff --git a/framework/I18N/core/MessageSource_gettext.php b/framework/I18N/core/MessageSource_gettext.php
index c92577d4..6849987f 100644
--- a/framework/I18N/core/MessageSource_gettext.php
+++ b/framework/I18N/core/MessageSource_gettext.php
@@ -432,9 +432,9 @@ class MessageSource_gettext extends MessageSource
$dir = dirname($mo_file);
if(!is_dir($dir))
- {
+ {
@mkdir($dir);
- @chmod($dir,0777);
+ @chmod($dir,PRADO_CHMOD);
}
if(!is_dir($dir))
throw new TException("Unable to create directory $dir");