summaryrefslogtreecommitdiff
path: root/framework/I18N/core
diff options
context:
space:
mode:
authorxue <>2006-04-03 21:55:33 +0000
committerxue <>2006-04-03 21:55:33 +0000
commit63c79dd722d5a8dd09b8828a4711d496680c0062 (patch)
tree1c535a0aa373a60d049aa669ab3d2944efdce4fa /framework/I18N/core
parentb3e1b298e6fa8e327516d54d62856599faf443d2 (diff)
Cleanup of I18N.
Diffstat (limited to 'framework/I18N/core')
-rw-r--r--framework/I18N/core/MessageSource_XLIFF.php222
-rw-r--r--framework/I18N/core/MessageSource_gettext.php218
2 files changed, 220 insertions, 220 deletions
diff --git a/framework/I18N/core/MessageSource_XLIFF.php b/framework/I18N/core/MessageSource_XLIFF.php
index a938342d..2194ca41 100644
--- a/framework/I18N/core/MessageSource_XLIFF.php
+++ b/framework/I18N/core/MessageSource_XLIFF.php
@@ -24,15 +24,15 @@ require_once(dirname(__FILE__).'/MessageSource.php');
/**
* MessageSource_XLIFF class.
- *
+ *
* Using XML XLIFF format as the message source for translation.
* Details and example of XLIFF can be found in the following URLs.
*
* # http://www.opentag.com/xliff.htm
* # http://www-106.ibm.com/developerworks/xml/library/x-localis2/
- *
+ *
* See the MessageSource::factory() method to instantiate this class.
- *
+ *
* @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version v1.0, last update on Fri Dec 24 16:18:44 EST 2004
* @package System.I18N.core
@@ -41,16 +41,16 @@ class MessageSource_XLIFF extends MessageSource
{
/**
* Message data filename extension.
- * @var string
+ * @var string
*/
- protected $dataExt = '.xml';
-
+ protected $dataExt = '.xml';
+
/**
* Separator between culture name and source.
- * @var string
+ * @var string
*/
protected $dataSeparator = '.';
-
+
/**
* Constructor.
* @param string the directory where the messages are stored.
@@ -58,7 +58,7 @@ class MessageSource_XLIFF extends MessageSource
*/
function __construct($source)
{
- $this->source = (string)$source;
+ $this->source = (string)$source;
}
/**
@@ -69,32 +69,32 @@ class MessageSource_XLIFF extends MessageSource
protected function &loadData($filename)
{
//load it.
-
+
$XML = simplexml_load_file($filename);
if(!$XML) return false;
$translationUnit = $XML->xpath('//trans-unit');
-
+
$translations = array();
-
+
foreach($translationUnit as $unit)
{
$source = (string)$unit->source;
$translations[$source][] = (string)$unit->target;
- $translations[$source][]= (string)$unit['id'];
- $translations[$source][]= (string)$unit->note;
- }
+ $translations[$source][]= (string)$unit['id'];
+ $translations[$source][]= (string)$unit->note;
+ }
return $translations;
}
-
+
/**
* Get the last modified unix-time for this particular catalogue+variant.
* Just use the file modified time.
* @param string catalogue+variant
* @return int last modified in unix-time format.
- */
+ */
protected function getLastModified($source)
{
if(is_file($source))
@@ -102,44 +102,44 @@ class MessageSource_XLIFF extends MessageSource
else
return 0;
}
-
+
/**
* Get the XLIFF file for a specific message catalogue and cultural
* vairant.
* @param string message catalogue
- * @return string full path to the XLIFF file.
+ * @return string full path to the XLIFF file.
*/
protected function getSource($variant)
{
return $this->source.'/'.$variant;
}
-
+
/**
* Determin if the XLIFF file source is valid.
* @param string XLIFF file
- * @return boolean true if valid, false otherwise.
+ * @return boolean true if valid, false otherwise.
*/
protected function isValidSource($source)
{
return is_file($source);
}
-
+
/**
* Get all the variants of a particular catalogue.
* @param string catalogue name
- * @return array list of all variants for this catalogue.
+ * @return array list of all variants for this catalogue.
*/
protected function getCatalogueList($catalogue)
{
$variants = explode('_',$this->culture);
$source = $catalogue.$this->dataExt;
-
+
$catalogues = array($source);
$variant = null;
-
+
for($i = 0, $k = count($variants); $i < $k; ++$i)
- {
+ {
if(isset($variants[$i]{0}))
{
$variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
@@ -147,24 +147,24 @@ class MessageSource_XLIFF extends MessageSource
$variant.$this->dataExt;
}
}
-
+
$byDir = $this->getCatalogueByDir($catalogue);
- $catalogues = array_merge($byDir,array_reverse($catalogues));
- return $catalogues;
+ $catalogues = array_merge($byDir,array_reverse($catalogues));
+ return $catalogues;
}
-
+
/**
* Traverse through the directory structure to find the catalogues.
* This should only be called by getCatalogueList()
* @param string a particular catalogue.
- * @return array a list of catalogues.
+ * @return array a list of catalogues.
* @see getCatalogueList()
*/
private function getCatalogueByDir($catalogue)
{
$variants = explode('_',$this->culture);
$catalogues = array();
-
+
$variant = null;
for($i = 0, $k = count($variants); $i < $k; ++$i)
@@ -176,43 +176,43 @@ class MessageSource_XLIFF extends MessageSource
}
}
return array_reverse($catalogues);
- }
-
+ }
+
/**
* Returns a list of catalogue and its culture ID.
* E.g. array('messages','en_AU')
- * @return array list of catalogues
+ * @return array list of catalogues
* @see getCatalogues()
*/
public function catalogues()
{
return $this->getCatalogues();
}
-
+
/**
* Returns a list of catalogue and its culture ID. This takes care
* of directory structures.
* E.g. array('messages','en_AU')
- * @return array list of catalogues
+ * @return array list of catalogues
*/
protected function getCatalogues($dir=null,$variant=null)
{
$dir = $dir?$dir:$this->source;
$files = scandir($dir);
-
+
$catalogue = array();
-
+
foreach($files as $file)
{
- if(is_dir($dir.'/'.$file)
+ if(is_dir($dir.'/'.$file)
&& preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file))
{
$catalogue = array_merge($catalogue,
$this->getCatalogues($dir.'/'.$file, $file));
}
-
- $pos = strpos($file,$this->dataExt);
- if($pos >0
+
+ $pos = strpos($file,$this->dataExt);
+ if($pos >0
&& substr($file,-1*strlen($this->dataExt)) == $this->dataExt)
{
$name = substr($file,0,$pos);
@@ -226,19 +226,19 @@ class MessageSource_XLIFF extends MessageSource
}
$details[0] = $cat;
$details[1] = $culture;
-
-
+
+
$catalogue[] = $details;
}
}
sort($catalogue);
return $catalogue;
- }
-
+ }
+
/**
* Get the variant for a catalogue depending on the current culture.
* @param string catalogue
- * @return string the variant.
+ * @return string the variant.
* @see save()
* @see update()
* @see delete()
@@ -247,7 +247,7 @@ class MessageSource_XLIFF extends MessageSource
{
if(is_null($catalogue))
$catalogue = 'messages';
-
+
foreach($this->getCatalogueList($catalogue) as $variant)
{
$file = $this->getSource($variant);
@@ -258,7 +258,7 @@ class MessageSource_XLIFF extends MessageSource
}
/**
- * Save the list of untranslated blocks to the translation source.
+ * Save the list of untranslated blocks to the translation source.
* If the translation was not found, you should add those
* strings to the translation source via the <b>append()</b> method.
* @param string the catalogue to add to
@@ -266,37 +266,37 @@ class MessageSource_XLIFF extends MessageSource
*/
public function save($catalogue='messages')
{
- $messages = $this->untranslated;
- if(count($messages) <= 0) return false;
+ $messages = $this->untranslated;
+ if(count($messages) <= 0) return false;
$variants = $this->getVariants($catalogue);
-
+
if($variants)
list($variant, $filename) = $variants;
else
list($variant, $filename) = $this->createMessageTemplate($catalogue);
-
- if(is_writable($filename) == false)
- throw new TMessageSourceIOException("Unable to save to file {$filename}, file must be writable.");
-
+
+ if(is_writable($filename) == false)
+ throw new TIOException("Unable to save to file {$filename}, file must be writable.");
+
//create a new dom, import the existing xml
$dom = DOMDocument::load($filename);
-
+
//find the body element
$xpath = new DomXPath($dom);
$body = $xpath->query('//body')->item(0);
-
+
$count = $xpath->query('//trans-unit')->length;
-
+
//for each message add it to the XML file using DOM
foreach($messages as $message)
{
$unit = $dom->createElement('trans-unit');
$unit->setAttribute('id',++$count);
-
- $source = $dom->createElement('source', $message);
+
+ $source = $dom->createElement('source', $message);
$target = $dom->createElement('target','');
-
+
$unit->appendChild($dom->createTextNode("\n"));
$unit->appendChild($source);
$unit->appendChild($dom->createTextNode("\n"));
@@ -307,63 +307,63 @@ class MessageSource_XLIFF extends MessageSource
$body->appendChild($unit);
$body->appendChild($dom->createTextNode("\n"));
}
-
-
+
+
$fileNode = $xpath->query('//file')->item(0);
$fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
-
+
//save it and clear the cache for this variant
$dom->save($filename);
if(!empty($this->cache))
$this->cache->clean($variant, $this->culture);
-
+
return true;
}
-
+
/**
* Update the translation.
* @param string the source string.
* @param string the new translation string.
* @param string comments
* @param string the catalogue to save to.
- * @return boolean true if translation was updated, false otherwise.
+ * @return boolean true if translation was updated, false otherwise.
*/
public function update($text, $target, $comments, $catalogue='messages')
- {
+ {
$variants = $this->getVariants($catalogue);
if($variants)
list($variant, $filename) = $variants;
else
- return false;
-
+ return false;
+
if(is_writable($filename) == false)
- throw new TMessageSourceIOException("Unable to update file {$filename}, file must be writable.");
-
+ throw new TIOException("Unable to update file {$filename}, file must be writable.");
+
//create a new dom, import the existing xml
$dom = DOMDocument::load($filename);
-
+
//find the body element
- $xpath = new DomXPath($dom);
+ $xpath = new DomXPath($dom);
$units = $xpath->query('//trans-unit');
-
+
//for each of the existin units
foreach($units as $unit)
{
$found = false;
$targetted = false;
$commented = false;
-
+
//in each unit, need to find the source, target and comment nodes
//it will assume that the source is before the target.
foreach($unit->childNodes as $node)
{
//source node
- if($node->nodeName == 'source'
+ if($node->nodeName == 'source'
&& $node->firstChild->wholeText == $text)
{
$found = true;
}
-
+
//found source, get the target and notes
if($found)
{
@@ -372,8 +372,8 @@ class MessageSource_XLIFF extends MessageSource
{
$node->nodeValue = $target;
$targetted = true;
- }
- //set the notes
+ }
+ //set the notes
if(!empty($comments) && $node->nodeName == 'note')
{
$node->nodeValue = $comments;
@@ -381,37 +381,37 @@ class MessageSource_XLIFF extends MessageSource
}
}
}
-
+
//append a target
if($found && !$targetted)
$unit->appendChild($dom->createElement('target',$target));
-
+
//append a note
if($found && !$commented && !empty($comments))
$unit->appendChild($dom->createElement('note',$comments));
-
+
//finished searching
if($found) break;
}
-
+
$fileNode = $xpath->query('//file')->item(0);
$fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
-
+
if($dom->save($filename) >0)
{
if(!empty($this->cache))
- $this->cache->clean($variant, $this->culture);
+ $this->cache->clean($variant, $this->culture);
return true;
}
-
+
return false;
}
-
+
/**
* Delete a particular message from the specified catalogue.
* @param string the source message to delete.
* @param string the catalogue to delete from.
- * @return boolean true if deleted, false otherwise.
+ * @return boolean true if deleted, false otherwise.
*/
public function delete($message, $catalogue='messages')
{
@@ -420,17 +420,17 @@ class MessageSource_XLIFF extends MessageSource
list($variant, $filename) = $variants;
else
return false;
-
- if(is_writable($filename) == false)
- throw new TMessageSourceIOException("Unable to modify file {$filename}, file must be writable.");
-
+
+ if(is_writable($filename) == false)
+ throw new TIOException("Unable to modify file {$filename}, file must be writable.");
+
//create a new dom, import the existing xml
$dom = DOMDocument::load($filename);
-
+
//find the body element
- $xpath = new DomXPath($dom);
+ $xpath = new DomXPath($dom);
$units = $xpath->query('//trans-unit');
-
+
//for each of the existin units
foreach($units as $unit)
{
@@ -439,27 +439,27 @@ class MessageSource_XLIFF extends MessageSource
foreach($unit->childNodes as $node)
{
//source node
- if($node->nodeName == 'source'
+ if($node->nodeName == 'source'
&& $node->firstChild->wholeText == $message)
{
-
+
//we found it, remove and save the xml file.
$unit->parentNode->removeChild($unit);
-
+
$fileNode = $xpath->query('//file')->item(0);
$fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z'));
-
+
if($dom->save($filename) >0)
{
if(!empty($this->cache))
- $this->cache->clean($variant, $this->culture);
+ $this->cache->clean($variant, $this->culture);
return true;
}
else return false;
-
+
}
}
-
+
}
return false;
@@ -467,14 +467,14 @@ class MessageSource_XLIFF extends MessageSource
protected function createMessageTemplate($catalogue)
{
- if(is_null($catalogue))
+ if(is_null($catalogue))
$catalogue = 'messages';
$variants = $this->getCatalogueList($catalogue);
$variant = array_shift($variants);
$file = $this->getSource($variant);
$dir = dirname($file);
if(!is_dir($dir)) @mkdir($dir);
- if(!is_dir($dir))
+ if(!is_dir($dir))
throw new TException("Unable to create directory $dir");
file_put_contents($file, $this->getTemplate($catalogue));
return array($variant, $file);
@@ -486,11 +486,11 @@ class MessageSource_XLIFF extends MessageSource
$xml = <<<EOD
<?xml version="1.0"?>
<xliff version="1.0">
- <file
- source-language="EN"
+ <file
+ source-language="EN"
target-language="{$this->culture}"
- datatype="plaintext"
- original="$catalogue"
+ datatype="plaintext"
+ original="$catalogue"
date="$date"
product-name="$catalogue">
<body>
diff --git a/framework/I18N/core/MessageSource_gettext.php b/framework/I18N/core/MessageSource_gettext.php
index b358a618..78fa5259 100644
--- a/framework/I18N/core/MessageSource_gettext.php
+++ b/framework/I18N/core/MessageSource_gettext.php
@@ -29,53 +29,53 @@ require_once(dirname(__FILE__).'/Gettext/TGettext.php');
/**
* MessageSource_gettext class.
- *
+ *
* Using Gettext MO format as the message source for translation.
* The gettext classes are based on PEAR's gettext MO and PO classes.
- *
+ *
* See the MessageSource::factory() method to instantiate this class.
- *
+ *
* @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version v1.0, last update on Fri Dec 24 16:18:44 EST 2004
* @package System.I18N.core
*/
class MessageSource_gettext extends MessageSource
-{
+{
/**
* Message data filename extension.
- * @var string
+ * @var string
*/
- protected $dataExt = '.mo';
-
+ protected $dataExt = '.mo';
+
/**
* PO data filename extension
- * @var string
+ * @var string
*/
protected $poExt = '.po';
-
+
/**
* Separator between culture name and source.
- * @var string
+ * @var string
*/
protected $dataSeparator = '.';
-
+
function __construct($source)
{
$this->source = (string)$source;
- }
-
+ }
+
/**
* Load the messages from a MO file.
* @param string MO file.
* @return array of messages.
- */
+ */
protected function &loadData($filename)
{
$mo = TGettext::factory('MO',$filename);
$mo->load();
$result = $mo->toArray();
-
+
$results = array();
$count=0;
foreach($result['strings'] as $source => $target)
@@ -83,61 +83,61 @@ class MessageSource_gettext extends MessageSource
$results[$source][] = $target; //target
$results[$source][] = $count++; //id
$results[$source][] = ''; //comments
- }
+ }
return $results;
}
-
+
/**
* Determin if the MO file source is valid.
* @param string MO file
- * @return boolean true if valid, false otherwise.
- */
+ * @return boolean true if valid, false otherwise.
+ */
protected function isValidSource($filename)
{
return is_file($filename);
}
-
+
/**
* Get the MO file for a specific message catalogue and cultural
* vairant.
* @param string message catalogue
- * @return string full path to the MO file.
- */
+ * @return string full path to the MO file.
+ */
protected function getSource($variant)
{
return $this->source.'/'.$variant;
}
-
+
/**
* Get the last modified unix-time for this particular catalogue+variant.
* Just use the file modified time.
* @param string catalogue+variant
* @return int last modified in unix-time format.
- */
+ */
protected function getLastModified($source)
{
if(is_file($source))
return filemtime($source);
else
return 0;
- }
-
+ }
+
/**
* Get all the variants of a particular catalogue.
* @param string catalogue name
- * @return array list of all variants for this catalogue.
+ * @return array list of all variants for this catalogue.
*/
protected function getCatalogueList($catalogue)
{
$variants = explode('_',$this->culture);
$source = $catalogue.$this->dataExt;
-
+
$catalogues = array($source);
$variant = null;
-
+
for($i = 0, $k = count($variants); $i < $k; ++$i)
- {
+ {
if(isset($variants[$i]{0}))
{
$variant .= ($variant)?'_'.$variants[$i]:$variants[$i];
@@ -146,23 +146,23 @@ class MessageSource_gettext extends MessageSource
}
}
$byDir = $this->getCatalogueByDir($catalogue);
- $catalogues = array_merge($byDir,array_reverse($catalogues));
+ $catalogues = array_merge($byDir,array_reverse($catalogues));
return $catalogues;
- }
+ }
+
-
/**
* Traverse through the directory structure to find the catalogues.
* This should only be called by getCatalogueList()
* @param string a particular catalogue.
- * @return array a list of catalogues.
+ * @return array a list of catalogues.
* @see getCatalogueList()
*/
private function getCatalogueByDir($catalogue)
{
$variants = explode('_',$this->culture);
$catalogues = array();
-
+
$variant = null;
for($i = 0, $k = count($variants); $i < $k; ++$i)
@@ -175,11 +175,11 @@ class MessageSource_gettext extends MessageSource
}
return array_reverse($catalogues);
}
-
+
/**
* Get the variant for a catalogue depending on the current culture.
* @param string catalogue
- * @return string the variant.
+ * @return string the variant.
* @see save()
* @see update()
* @see delete()
@@ -188,7 +188,7 @@ class MessageSource_gettext extends MessageSource
{
if(is_null($catalogue))
$catalogue = 'messages';
-
+
foreach($this->getCatalogueList($catalogue) as $variant)
{
$file = $this->getSource($variant);
@@ -198,79 +198,79 @@ class MessageSource_gettext extends MessageSource
}
return false;
}
-
+
private function getPOFile($MOFile)
{
$filebase = substr($MOFile, 0, strlen($MOFile)-strlen($this->dataExt));
return $filebase.$this->poExt;
}
-
+
/**
- * Save the list of untranslated blocks to the translation source.
+ * Save the list of untranslated blocks to the translation source.
* If the translation was not found, you should add those
* strings to the translation source via the <b>append()</b> method.
* @param string the catalogue to add to
- * @return boolean true if saved successfuly, false otherwise.
+ * @return boolean true if saved successfuly, false otherwise.
*/
function save($catalogue='messages')
{
$messages = $this->untranslated;
-
+
if(count($messages) <= 0) return false;
-
+
$variants = $this->getVariants($catalogue);
-
+
if($variants)
list($variant, $MOFile, $POFile) = $variants;
else
- list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue);
-
- if(is_writable($MOFile) == false)
- throw new TMessageSourceIOException("Unable to save to file {$MOFile}, file must be writable.");
+ list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue);
+
+ if(is_writable($MOFile) == false)
+ throw new TIOException("Unable to save to file {$MOFile}, file must be writable.");
if(is_writable($POFile) == false)
- throw new TMessageSourceIOException("Unable to save to file {$POFile}, file must be writable.");
-
+ throw new TIOException("Unable to save to file {$POFile}, file must be writable.");
+
//set the strings as untranslated.
$strings = array();
foreach($messages as $message)
- $strings[$message] = '';
-
+ $strings[$message] = '';
+
//load the PO
$po = TGettext::factory('PO',$POFile);
$po->load();
$result = $po->toArray();
-
+
$existing = count($result['strings']);
-
+
//add to strings to the existing message list
- $result['strings'] = array_merge($result['strings'],$strings);
-
+ $result['strings'] = array_merge($result['strings'],$strings);
+
$new = count($result['strings']);
-
+
if($new > $existing)
- {
+ {
//change the date 2004-12-25 12:26
$result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
-
+
$po->fromArray($result);
$mo = $po->toMO();
if($po->save() && $mo->save($MOFile))
{
- if(!empty($this->cache))
- $this->cache->clean($variant, $this->culture);
+ if(!empty($this->cache))
+ $this->cache->clean($variant, $this->culture);
return true;
}
else
return false;
}
return false;
- }
+ }
/**
* Delete a particular message from the specified catalogue.
* @param string the source message to delete.
* @param string the catalogue to delete from.
- * @return boolean true if deleted, false otherwise.
+ * @return boolean true if deleted, false otherwise.
*/
function delete($message, $catalogue='messages')
{
@@ -279,47 +279,47 @@ class MessageSource_gettext extends MessageSource
list($variant, $MOFile, $POFile) = $variants;
else
return false;
-
+
if(is_writable($MOFile) == false)
- throw new TMessageSourceIOException("Unable to modify file {$MOFile}, file must be writable.");
+ throw new TIOException("Unable to modify file {$MOFile}, file must be writable.");
if(is_writable($POFile) == false)
- throw new TMessageSourceIOException("Unable to modify file {$POFile}, file must be writable.");
-
+ throw new TIOException("Unable to modify file {$POFile}, file must be writable.");
+
$po = TGettext::factory('PO',$POFile);
$po->load();
- $result = $po->toArray();
-
+ $result = $po->toArray();
+
foreach($result['strings'] as $string => $value)
{
if($string == $message)
{
$result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
unset($result['strings'][$string]);
-
+
$po->fromArray($result);
$mo = $po->toMO();
if($po->save() && $mo->save($MOFile))
{
if(!empty($this->cache))
$this->cache->clean($variant, $this->culture);
- return true;
+ return true;
}
else
- return false;
+ return false;
}
}
-
+
return false;
}
-
+
/**
* Update the translation.
* @param string the source string.
* @param string the new translation string.
* @param string comments
* @param string the catalogue of the translation.
- * @return boolean true if translation was updated, false otherwise.
- */
+ * @return boolean true if translation was updated, false otherwise.
+ */
function update($text, $target, $comments, $catalogue='messages')
{
$variants = $this->getVariants($catalogue);
@@ -327,77 +327,77 @@ class MessageSource_gettext extends MessageSource
list($variant, $MOFile, $POFile) = $variants;
else
return false;
-
+
if(is_writable($MOFile) == false)
- throw new TMessageSourceIOException("Unable to update file {$MOFile}, file must be writable.");
+ throw new TIOException("Unable to update file {$MOFile}, file must be writable.");
if(is_writable($POFile) == false)
- throw new TMessageSourceIOException("Unable to update file {$POFile}, file must be writable.");
-
-
+ throw new TIOException("Unable to update file {$POFile}, file must be writable.");
+
+
$po = TGettext::factory('PO',$POFile);
$po->load();
- $result = $po->toArray();
-
+ $result = $po->toArray();
+
foreach($result['strings'] as $string => $value)
{
if($string == $text)
{
$result['strings'][$string] = $target;
$result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
-
+
$po->fromArray($result);
$mo = $po->toMO();
-
+
if($po->save() && $mo->save($MOFile))
{
if(!empty($this->cache))
$this->cache->clean($variant, $this->culture);
- return true;
+ return true;
}
else
return false;
}
- }
-
+ }
+
return false;
}
-
-
+
+
/**
* Returns a list of catalogue as key and all it variants as value.
- * @return array list of catalogues
+ * @return array list of catalogues
*/
function catalogues()
{
return $this->getCatalogues();
}
-
+
/**
* Returns a list of catalogue and its culture ID. This takes care
* of directory structures.
* E.g. array('messages','en_AU')
- * @return array list of catalogues
+ * @return array list of catalogues
*/
protected function getCatalogues($dir=null,$variant=null)
{
$dir = $dir?$dir:$this->source;
$files = scandir($dir);
-
+
$catalogue = array();
-
+
foreach($files as $file)
- {
- if(is_dir($dir.'/'.$file)
+ {
+ if(is_dir($dir.'/'.$file)
&& preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file))
{
-
+
$catalogue = array_merge($catalogue,
$this->getCatalogues($dir.'/'.$file, $file));
}
-
+
$pos = strpos($file,$this->dataExt);
-
- if($pos >0
+
+ if($pos >0
&& substr($file,-1*strlen($this->dataExt)) == $this->dataExt)
{
$name = substr($file,0,$pos);
@@ -411,19 +411,19 @@ class MessageSource_gettext extends MessageSource
}
$details[0] = $cat;
$details[1] = $culture;
-
-
+
+
$catalogue[] = $details;
}
}
sort($catalogue);
-
+
return $catalogue;
- }
+ }
protected function createMessageTemplate($catalogue)
{
- if(is_null($catalogue))
+ if(is_null($catalogue))
$catalogue = 'messages';
$variants = $this->getCatalogueList($catalogue);
$variant = array_shift($variants);
@@ -432,13 +432,13 @@ class MessageSource_gettext extends MessageSource
$dir = dirname($mo_file);
if(!is_dir($dir)) @mkdir($dir);
- if(!is_dir($dir))
+ if(!is_dir($dir))
throw new TException("Unable to create directory $dir");
$po = TGettext::factory('PO',$po_file);
$result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s');
$result['strings'] = array();
-
+
$po->fromArray($result);
$mo = $po->toMO();
if($po->save() && $mo->save($mo_file))