[limb-svn] r6351 - in 3.x/trunk/limb: cms/src/controller config/src i18n/src/toolkit i18n/src/translation

svn at limb-project.com svn at limb-project.com
Mon Oct 1 17:33:02 MSD 2007


Author: pachanga
Date: 2007-10-01 17:33:02 +0400 (Mon, 01 Oct 2007)
New Revision: 6351
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6351

Modified:
   3.x/trunk/limb/cms/src/controller/CRUDController.class.php
   3.x/trunk/limb/config/src/lmbConfTools.class.php
   3.x/trunk/limb/i18n/src/toolkit/lmbI18NTools.class.php
   3.x/trunk/limb/i18n/src/translation/lmbQtDictionaryBackend.class.php
Log:
-- eol style changes

Modified: 3.x/trunk/limb/cms/src/controller/CRUDController.class.php
===================================================================
--- 3.x/trunk/limb/cms/src/controller/CRUDController.class.php	2007-10-01 13:31:08 UTC (rev 6350)
+++ 3.x/trunk/limb/cms/src/controller/CRUDController.class.php	2007-10-01 13:33:02 UTC (rev 6351)
@@ -1,114 +1,114 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
-/**
- * @package cms
- * @version $Id$
- */
-
-lmb_require('limb/web_app/src/controller/lmbController.class.php');
- at define('LIMB_MODELS_INCLUDE_PATH', 'src/model;limb/*/src/model');
-
-class CRUDController extends lmbController 
-{
-  protected $class_name;
-  protected $model_name;
-  
-  function performAction() 
-  {   
-    $this->model_name = $this->request->get('controller');
-    $this->class_name = lmb_camel_case($this->model_name );
-  
-    try 
-    {
-      $file_model = $this->toolkit->findFileByAlias($this->class_name . '.class.php', LIMB_MODELS_INCLUDE_PATH, 'model');
-      lmb_require($file_model);
-      
-      parent :: performAction();
-    } catch(lmbException $e) 
-    {
-      $this->forward('not_found', 'display');
-    } 
-  }
-  
-  function doDisplay () 
-  {
-    $this->passToView($this->model_name . '_list', lmbActiveRecord :: find($this->class_name , ''));
-    $this->passToView('CRUD_list', lmbActiveRecord :: find($this->class_name , ''));
-  }
-  
-  function doCreate() 
-  {
-		$CRUD_object= new $this->class_name();
-	
-    $this->_performCreateOrEdit($CRUD_object);
-  }
-
-  function doEdit() 
-  {
-		$id = (int)$this->request->getInteger('id');
-		
-		$CRUD_object = new $this->class_name($id);
-	
-    $this->_performCreateOrEdit($CRUD_object);
-  }
-	
-  function doDelete() 
-  {
-    $id = (int)$this->request->getInteger('id');
-    
-    $CRUD_object = new $this->class_name($id);
-    $CRUD_object->destroy();
-    
-    $this->redirect();
-  }	
-  
-  function getName() 
-  {
-    return $this->model_name;
-  }
-  
-  protected function _performCreateOrEdit($CRUD_object) 
-  {
-    if( $this->view->findChild('CRUD_form') ) 
-		  $this->useForm('CRUD_form');  
-		else
-		  $this->useForm($this->model_name . '_form');   
-    
-    $this->setFormDatasource($CRUD_object);
-
-    if( $this->request->hasPost() ) 
-    {
-      $CRUD_object->import($this->request);
-      $CRUD_object->validate($this->error_list);
-
-      if( $this->error_list->isEmpty() ) 
-      {
-        $CRUD_object->saveSkipValidation();
-        $this->redirect();
-      }
-    }
-  }
-  
-  protected function _findTemplateForAction($action)
-  {
-    parent :: _findTemplateForAction($action);
-    
-    if( !$this->view->getTemplate() ) 
-    {  
-      $template_path = $this->name . '/' . $action . '.html';
-
-      $wact_locator = lmbToolkit :: instance()->getWactLocator();
-
-      if( $wact_locator->locateSourceTemplate($template_path)) 
-        $this->setTemplate($template_path);
-    }
-  }
-}
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+/**
+ * @package cms
+ * @version $Id$
+ */
+
+lmb_require('limb/web_app/src/controller/lmbController.class.php');
+ at define('LIMB_MODELS_INCLUDE_PATH', 'src/model;limb/*/src/model');
+
+class CRUDController extends lmbController 
+{
+  protected $class_name;
+  protected $model_name;
+  
+  function performAction() 
+  {   
+    $this->model_name = $this->request->get('controller');
+    $this->class_name = lmb_camel_case($this->model_name );
+  
+    try 
+    {
+      $file_model = $this->toolkit->findFileByAlias($this->class_name . '.class.php', LIMB_MODELS_INCLUDE_PATH, 'model');
+      lmb_require($file_model);
+      
+      parent :: performAction();
+    } catch(lmbException $e) 
+    {
+      $this->forward('not_found', 'display');
+    } 
+  }
+  
+  function doDisplay () 
+  {
+    $this->passToView($this->model_name . '_list', lmbActiveRecord :: find($this->class_name , ''));
+    $this->passToView('CRUD_list', lmbActiveRecord :: find($this->class_name , ''));
+  }
+  
+  function doCreate() 
+  {
+		$CRUD_object= new $this->class_name();
+	
+    $this->_performCreateOrEdit($CRUD_object);
+  }
+
+  function doEdit() 
+  {
+		$id = (int)$this->request->getInteger('id');
+		
+		$CRUD_object = new $this->class_name($id);
+	
+    $this->_performCreateOrEdit($CRUD_object);
+  }
+	
+  function doDelete() 
+  {
+    $id = (int)$this->request->getInteger('id');
+    
+    $CRUD_object = new $this->class_name($id);
+    $CRUD_object->destroy();
+    
+    $this->redirect();
+  }	
+  
+  function getName() 
+  {
+    return $this->model_name;
+  }
+  
+  protected function _performCreateOrEdit($CRUD_object) 
+  {
+    if( $this->view->findChild('CRUD_form') ) 
+		  $this->useForm('CRUD_form');  
+		else
+		  $this->useForm($this->model_name . '_form');   
+    
+    $this->setFormDatasource($CRUD_object);
+
+    if( $this->request->hasPost() ) 
+    {
+      $CRUD_object->import($this->request);
+      $CRUD_object->validate($this->error_list);
+
+      if( $this->error_list->isEmpty() ) 
+      {
+        $CRUD_object->saveSkipValidation();
+        $this->redirect();
+      }
+    }
+  }
+  
+  protected function _findTemplateForAction($action)
+  {
+    parent :: _findTemplateForAction($action);
+    
+    if( !$this->view->getTemplate() ) 
+    {  
+      $template_path = $this->name . '/' . $action . '.html';
+
+      $wact_locator = lmbToolkit :: instance()->getWactLocator();
+
+      if( $wact_locator->locateSourceTemplate($template_path)) 
+        $this->setTemplate($template_path);
+    }
+  }
+}
+

Modified: 3.x/trunk/limb/config/src/lmbConfTools.class.php
===================================================================
--- 3.x/trunk/limb/config/src/lmbConfTools.class.php	2007-10-01 13:31:08 UTC (rev 6350)
+++ 3.x/trunk/limb/config/src/lmbConfTools.class.php	2007-10-01 13:33:02 UTC (rev 6351)
@@ -1,70 +1,70 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- */
-lmb_require('limb/toolkit/src/lmbAbstractTools.class.php');
-lmb_require('limb/config/src/lmbIni.class.php');
-lmb_require('limb/config/src/lmbCachedIni.class.php');
-lmb_require('limb/config/src/lmbConf.class.php');
-
- at define('LIMB_CONF_INCLUDE_PATH', 'settings;limb/*/settings');
-
-/**
- * class lmbConfTools.
- *
- * @package config
- * @version $Id$
- */
-class lmbConfTools extends lmbAbstractTools
-{
-  protected $confs = array();
-
-  function setConf($name, $conf)
-  {
-    $this->confs[$this->_normalizeConfName($name)] = $conf;
-  }
-
-  function getConf($name)
-  {
-    $name = $this->_normalizeConfName($name);
-
-    if(isset($this->confs[$name]))
-      return $this->confs[$name];
-
-    $ext = substr($name, strpos($name, '.'));
-
-    if($ext == '.ini')
-    {
-      $file = $this->_locateFile($name);
-      if(defined('LIMB_VAR_DIR'))
-        $this->confs[$name] = new lmbCachedIni($file, LIMB_VAR_DIR . '/ini/');
-      else
-        $this->confs[$name] = new lmbIni($file);
-    }
-    elseif($ext == '.conf.php')
-    {
-      $this->confs[$name] = new lmbConf($this->_locateFile($name));
-    }
-    else
-      throw new lmbException("'$ext' type configuration is not supported!");
-
-    return $this->confs[$name];
-  }
-
-  protected function _locateFile($name)
-  {
-    return $this->toolkit->findFileByAlias($name, LIMB_CONF_INCLUDE_PATH, 'config');
-  }
-
-  protected function _normalizeConfName($name)
-  {
-    if(strpos($name, '.') !== false)
-      return $name;
-    return "$name.conf.php";
-  }
-}
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/toolkit/src/lmbAbstractTools.class.php');
+lmb_require('limb/config/src/lmbIni.class.php');
+lmb_require('limb/config/src/lmbCachedIni.class.php');
+lmb_require('limb/config/src/lmbConf.class.php');
+
+ at define('LIMB_CONF_INCLUDE_PATH', 'settings;limb/*/settings');
+
+/**
+ * class lmbConfTools.
+ *
+ * @package config
+ * @version $Id$
+ */
+class lmbConfTools extends lmbAbstractTools
+{
+  protected $confs = array();
+
+  function setConf($name, $conf)
+  {
+    $this->confs[$this->_normalizeConfName($name)] = $conf;
+  }
+
+  function getConf($name)
+  {
+    $name = $this->_normalizeConfName($name);
+
+    if(isset($this->confs[$name]))
+      return $this->confs[$name];
+
+    $ext = substr($name, strpos($name, '.'));
+
+    if($ext == '.ini')
+    {
+      $file = $this->_locateFile($name);
+      if(defined('LIMB_VAR_DIR'))
+        $this->confs[$name] = new lmbCachedIni($file, LIMB_VAR_DIR . '/ini/');
+      else
+        $this->confs[$name] = new lmbIni($file);
+    }
+    elseif($ext == '.conf.php')
+    {
+      $this->confs[$name] = new lmbConf($this->_locateFile($name));
+    }
+    else
+      throw new lmbException("'$ext' type configuration is not supported!");
+
+    return $this->confs[$name];
+  }
+
+  protected function _locateFile($name)
+  {
+    return $this->toolkit->findFileByAlias($name, LIMB_CONF_INCLUDE_PATH, 'config');
+  }
+
+  protected function _normalizeConfName($name)
+  {
+    if(strpos($name, '.') !== false)
+      return $name;
+    return "$name.conf.php";
+  }
+}
+

Modified: 3.x/trunk/limb/i18n/src/toolkit/lmbI18NTools.class.php
===================================================================
--- 3.x/trunk/limb/i18n/src/toolkit/lmbI18NTools.class.php	2007-10-01 13:31:08 UTC (rev 6350)
+++ 3.x/trunk/limb/i18n/src/toolkit/lmbI18NTools.class.php	2007-10-01 13:33:02 UTC (rev 6351)
@@ -1,127 +1,127 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- */
-lmb_require('limb/toolkit/src/lmbAbstractTools.class.php');
-lmb_require('limb/i18n/src/locale/lmbLocale.class.php');
-lmb_require('limb/i18n/src/translation/lmbQtDictionaryBackend.class.php');
-
- at define('LIMB_LOCALE_INCLUDE_PATH', 'i18n/locale;limb/i18n/i18n/locale');
-
-/**
- * class lmbI18NTools.
- *
- * @package i18n
- * @version $Id$
- */
-class lmbI18NTools extends lmbAbstractTools
-{
-  protected $current_locale;
-  protected $locale_objects = array();
-  protected $dictionaries = array();
-  protected $dict_backend;
-
-  function getDictionaryBackend()
-  {
-    if(!is_object($this->dict_backend))
-    {
-      $this->dict_backend = new lmbQtDictionaryBackend();
-      if(defined('LIMB_VAR_DIR'))
-      {
-        $this->dict_backend->setCacheDir(LIMB_VAR_DIR);
-        $this->dict_backend->useCache();
-      }
-    }
-
-    return $this->dict_backend;
-  }
-
-  function setDictionaryBackend($backend)
-  {
-    $this->dict_backend = $backend;
-  }
-
-  function getLocale()
-  {
-    if(!$this->current_locale)
-      $this->current_locale = 'en_US';
-
-    return $this->current_locale;
-  }
-
-  function setLocale($locale)
-  {
-    $this->current_locale = $locale;
-  }
-
-  function getLocaleObject($locale = null)
-  {
-    if(!$locale)
-      $locale = $this->getLocale();
-
-    if(!isset($this->locale_objects[$locale]))
-      $this->locale_objects[$locale] = $this->createLocaleObject($locale);
-
-    return $this->locale_objects[$locale];
-  }
-
-  function addLocaleObject($obj, $locale = null)
-  {
-    if(!$locale)
-      $locale = $obj->getLocaleString();
-
-    $this->locale_objects[$locale] = $obj;
-  }
-
-  function createLocaleObject($locale)
-  {
-    $file = $this->toolkit->findFileByAlias($locale . '.ini', LIMB_LOCALE_INCLUDE_PATH, 'i18n');
-
-    if(defined('LIMB_VAR_DIR'))
-      return new lmbLocale($locale, new lmbCachedIni($file, LIMB_VAR_DIR . '/locale/'));
-    else
-      return new lmbLocale($locale, new lmbIni($file));
-  }
-
-  function getDictionary($locale, $domain)
-  {
-    if(!isset($this->dictionaries[$locale . '@' . $domain]))
-    {
-      $backend = $this->getDictionaryBackend();
-      $this->dictionaries[$locale . '@' . $domain] = $backend->load($locale, $domain);
-    }
-
-    return $this->dictionaries[$locale . '@' . $domain];
-  }
-
-  function setDictionary($locale, $domain, $dict)
-  {
-    $this->dictionaries[$locale . '@' . $domain] = $dict;
-  }
-
-  function translate($text, $arg1 = null, $arg2 = null)
-  {
-    $locale = $this->getLocale();
-
-    $domain = 'default';
-    $attributes = null;
-
-    if(is_array($arg1))
-    {
-      $attributes = $arg1;
-      if(is_string($arg2))
-        $domain = $arg2;
-    }
-    elseif(is_string($arg1))
-      $domain = $arg1;
-
-    if($dict = $this->getDictionary($locale, $domain))
-      return $dict->translate($text, $attributes);
-    else
-      return $text;
-  }
-}
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/toolkit/src/lmbAbstractTools.class.php');
+lmb_require('limb/i18n/src/locale/lmbLocale.class.php');
+lmb_require('limb/i18n/src/translation/lmbQtDictionaryBackend.class.php');
+
+ at define('LIMB_LOCALE_INCLUDE_PATH', 'i18n/locale;limb/i18n/i18n/locale');
+
+/**
+ * class lmbI18NTools.
+ *
+ * @package i18n
+ * @version $Id$
+ */
+class lmbI18NTools extends lmbAbstractTools
+{
+  protected $current_locale;
+  protected $locale_objects = array();
+  protected $dictionaries = array();
+  protected $dict_backend;
+
+  function getDictionaryBackend()
+  {
+    if(!is_object($this->dict_backend))
+    {
+      $this->dict_backend = new lmbQtDictionaryBackend();
+      if(defined('LIMB_VAR_DIR'))
+      {
+        $this->dict_backend->setCacheDir(LIMB_VAR_DIR);
+        $this->dict_backend->useCache();
+      }
+    }
+
+    return $this->dict_backend;
+  }
+
+  function setDictionaryBackend($backend)
+  {
+    $this->dict_backend = $backend;
+  }
+
+  function getLocale()
+  {
+    if(!$this->current_locale)
+      $this->current_locale = 'en_US';
+
+    return $this->current_locale;
+  }
+
+  function setLocale($locale)
+  {
+    $this->current_locale = $locale;
+  }
+
+  function getLocaleObject($locale = null)
+  {
+    if(!$locale)
+      $locale = $this->getLocale();
+
+    if(!isset($this->locale_objects[$locale]))
+      $this->locale_objects[$locale] = $this->createLocaleObject($locale);
+
+    return $this->locale_objects[$locale];
+  }
+
+  function addLocaleObject($obj, $locale = null)
+  {
+    if(!$locale)
+      $locale = $obj->getLocaleString();
+
+    $this->locale_objects[$locale] = $obj;
+  }
+
+  function createLocaleObject($locale)
+  {
+    $file = $this->toolkit->findFileByAlias($locale . '.ini', LIMB_LOCALE_INCLUDE_PATH, 'i18n');
+
+    if(defined('LIMB_VAR_DIR'))
+      return new lmbLocale($locale, new lmbCachedIni($file, LIMB_VAR_DIR . '/locale/'));
+    else
+      return new lmbLocale($locale, new lmbIni($file));
+  }
+
+  function getDictionary($locale, $domain)
+  {
+    if(!isset($this->dictionaries[$locale . '@' . $domain]))
+    {
+      $backend = $this->getDictionaryBackend();
+      $this->dictionaries[$locale . '@' . $domain] = $backend->load($locale, $domain);
+    }
+
+    return $this->dictionaries[$locale . '@' . $domain];
+  }
+
+  function setDictionary($locale, $domain, $dict)
+  {
+    $this->dictionaries[$locale . '@' . $domain] = $dict;
+  }
+
+  function translate($text, $arg1 = null, $arg2 = null)
+  {
+    $locale = $this->getLocale();
+
+    $domain = 'default';
+    $attributes = null;
+
+    if(is_array($arg1))
+    {
+      $attributes = $arg1;
+      if(is_string($arg2))
+        $domain = $arg2;
+    }
+    elseif(is_string($arg1))
+      $domain = $arg1;
+
+    if($dict = $this->getDictionary($locale, $domain))
+      return $dict->translate($text, $attributes);
+    else
+      return $text;
+  }
+}

Modified: 3.x/trunk/limb/i18n/src/translation/lmbQtDictionaryBackend.class.php
===================================================================
--- 3.x/trunk/limb/i18n/src/translation/lmbQtDictionaryBackend.class.php	2007-10-01 13:31:08 UTC (rev 6350)
+++ 3.x/trunk/limb/i18n/src/translation/lmbQtDictionaryBackend.class.php	2007-10-01 13:33:02 UTC (rev 6351)
@@ -1,205 +1,205 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- */
-lmb_require('limb/i18n/src/translation/lmbI18NDictionary.class.php');
-lmb_require('limb/fs/src/exception/lmbFileNotFoundException.class.php');
-
- at define('LIMB_TRANSLATIONS_INCLUDE_PATH', 'i18n/translations;limb/*/i18n/translations');
-
-/**
- * class lmbQtDictionaryBackend.
- *
- * @package i18n
- * @version $Id$
- */
-class lmbQtDictionaryBackend //extends lmbDictionaryBackend ???
-{
-  protected $use_cache = false;
-  protected $cache_dir;
-
-  function __construct()
-  {
-    $this->search_path = LIMB_TRANSLATIONS_INCLUDE_PATH;
-  }
-
-  function setCacheDir($dir)
-  {
-    $this->cache_dir = $dir;
-  }
-
-  function useCache($flag = true)
-  {
-    $this->use_cache = $flag;
-  }
-
-  function setSearchPath($path)
-  {
-    $this->search_path = $path;
-  }
-
-  function load($locale, $domain)
-  {
-    $file = $this->mapToFile($locale, $domain);
-    return $this->loadFromFile($file);
-  }
-
-  function save($locale, $domain, $dict)
-  {
-    $file = $this->mapToFile($locale, $domain);
-    return $this->saveToFile($file, $dict);
-  }
-
-  function loadAll()
-  {
-    $locator = lmbToolkit :: instance()->getFileLocator($this->search_path, 'i18n');
-    $dicts = array();
-    $files = $locator->locateAll('*.ts');
-
-    foreach($files as $file)
-    {
-      list($domain, $locale, ) = explode('.', basename($file));
-      $dicts[$locale][$domain] = $this->loadFromFile($file);
-    }
-
-    return $dicts;
-  }
-
-  function info($locale, $domain)
-  {
-    $file = $this->mapToFile($locale, $domain);
-    return "Qt dictionary contained in '$file', locale '$locale', domain '$domain'";
-  }
-
-  function mapToFile($locale, $domain)
-  {
-    return lmbToolkit :: instance()->findFileByAlias($domain . '.' . $locale . '.ts', $this->search_path, 'i18n');
-  }
-
-  function getDOMDocument($dictionary)
-  {
-    $doc = new DOMDocument('1.0', 'utf-8');
-    $doc->formatOutput = true; // pretty printing
-
-    $ts_node = $doc->createElement('TS');
-    $doc->appendChild($ts_node);
-
-    $translations = $dictionary->getTranslations();
-    $context_node = $doc->createElement('context');
-
-    foreach($translations as $text => $translation)
-    {
-      $message_node = $doc->createElement('message');
-      $text_node = $doc->createElement('source');
-      $translation_node = $doc->createElement('translation');
-
-      $text_node->appendChild($doc->createTextNode($text));
-
-      if(empty($translation))
-        $translation_node->setAttribute('type', 'unfinished');
-      else
-        $translation_node->appendChild($doc->createTextNode($translation));
-
-      $message_node->appendChild($text_node);
-      $message_node->appendChild($translation_node);
-
-      $context_node->appendChild($message_node);
-
-      $ts_node->appendChild($context_node);
-    }
-    return $doc;
-  }
-
-  function loadFromXML($xml)
-  {
-    $dictionary = new lmbI18NDictionary();
-    $this->_parseXML($dictionary, $xml);
-    return $dictionary;
-  }
-
-  function loadFromFile($file)
-  {
-    if(!file_exists($file))
-      throw new lmbFileNotFoundException($file, "translations file $file not found");
-
-    $dictionary = new lmbI18NDictionary();
-
-    if(!$this->_loadFromCache($dictionary, $file))
-    {
-      try
-      {
-        $this->_parseXML($dictionary, file_get_contents($file));
-      }
-      catch(lmbException $e)
-      {
-        throw new lmbException($e->getMessage() . " at file '" . $file . "'");
-      }
-      $this->_saveToCache($dictionary, $file);
-    }
-    return $dictionary;
-  }
-
-  protected function _parseXML($dictionary, $xml)
-  {
-    if(!$xml_doc = simplexml_load_string($xml))
-    {
-      throw new lmbException('SimpleXML parsing error');
-    }
-
-    foreach($xml_doc->context as $context)
-    {
-      foreach($context->message as $message)
-      {
-        if($translation = trim((string)$message->translation))
-          $dictionary->add((string)$message->source, $translation);
-        else
-          $dictionary->add((string)$message->source);
-      }
-    }
-    return true;
-  }
-
-  function saveToFile($file, $dictionary)
-  {
-    $this->getDOMDocument($dictionary)->save($file);
-  }
-
-  protected function _isFileCachingOn()
-  {
-    return $this->use_cache && $this->cache_dir;
-  }
-
-  protected function _loadFromCache($dictionary, $file)
-  {
-    if(!$this->_isFileCachingOn())
-      return false;
-
-    if(!file_exists($cache = $this->_getCacheFile($file)))
-      return false;
-
-    $dictionary->setTranslations(unserialize(file_get_contents($cache)));
-    return true;
-  }
-
-  protected function _saveToCache($dictionary, $file)
-  {
-    if(!$this->_isFileCachingOn())
-      return;
-
-    $cache = $this->_getCacheFile($file);
-    if(!is_dir($dir = dirname($cache)))
-      mkdir($dir);
-    file_put_contents($this->_getCacheFile($file), serialize($dictionary->getTranslations()), LOCK_EX);
-  }
-
-  protected function _getCacheFile($file)
-  {
-    return $this->cache_dir . '/i18n-qt/' . md5(realpath($file));
-  }
-}
-
-
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/i18n/src/translation/lmbI18NDictionary.class.php');
+lmb_require('limb/fs/src/exception/lmbFileNotFoundException.class.php');
+
+ at define('LIMB_TRANSLATIONS_INCLUDE_PATH', 'i18n/translations;limb/*/i18n/translations');
+
+/**
+ * class lmbQtDictionaryBackend.
+ *
+ * @package i18n
+ * @version $Id$
+ */
+class lmbQtDictionaryBackend //extends lmbDictionaryBackend ???
+{
+  protected $use_cache = false;
+  protected $cache_dir;
+
+  function __construct()
+  {
+    $this->search_path = LIMB_TRANSLATIONS_INCLUDE_PATH;
+  }
+
+  function setCacheDir($dir)
+  {
+    $this->cache_dir = $dir;
+  }
+
+  function useCache($flag = true)
+  {
+    $this->use_cache = $flag;
+  }
+
+  function setSearchPath($path)
+  {
+    $this->search_path = $path;
+  }
+
+  function load($locale, $domain)
+  {
+    $file = $this->mapToFile($locale, $domain);
+    return $this->loadFromFile($file);
+  }
+
+  function save($locale, $domain, $dict)
+  {
+    $file = $this->mapToFile($locale, $domain);
+    return $this->saveToFile($file, $dict);
+  }
+
+  function loadAll()
+  {
+    $locator = lmbToolkit :: instance()->getFileLocator($this->search_path, 'i18n');
+    $dicts = array();
+    $files = $locator->locateAll('*.ts');
+
+    foreach($files as $file)
+    {
+      list($domain, $locale, ) = explode('.', basename($file));
+      $dicts[$locale][$domain] = $this->loadFromFile($file);
+    }
+
+    return $dicts;
+  }
+
+  function info($locale, $domain)
+  {
+    $file = $this->mapToFile($locale, $domain);
+    return "Qt dictionary contained in '$file', locale '$locale', domain '$domain'";
+  }
+
+  function mapToFile($locale, $domain)
+  {
+    return lmbToolkit :: instance()->findFileByAlias($domain . '.' . $locale . '.ts', $this->search_path, 'i18n');
+  }
+
+  function getDOMDocument($dictionary)
+  {
+    $doc = new DOMDocument('1.0', 'utf-8');
+    $doc->formatOutput = true; // pretty printing
+
+    $ts_node = $doc->createElement('TS');
+    $doc->appendChild($ts_node);
+
+    $translations = $dictionary->getTranslations();
+    $context_node = $doc->createElement('context');
+
+    foreach($translations as $text => $translation)
+    {
+      $message_node = $doc->createElement('message');
+      $text_node = $doc->createElement('source');
+      $translation_node = $doc->createElement('translation');
+
+      $text_node->appendChild($doc->createTextNode($text));
+
+      if(empty($translation))
+        $translation_node->setAttribute('type', 'unfinished');
+      else
+        $translation_node->appendChild($doc->createTextNode($translation));
+
+      $message_node->appendChild($text_node);
+      $message_node->appendChild($translation_node);
+
+      $context_node->appendChild($message_node);
+
+      $ts_node->appendChild($context_node);
+    }
+    return $doc;
+  }
+
+  function loadFromXML($xml)
+  {
+    $dictionary = new lmbI18NDictionary();
+    $this->_parseXML($dictionary, $xml);
+    return $dictionary;
+  }
+
+  function loadFromFile($file)
+  {
+    if(!file_exists($file))
+      throw new lmbFileNotFoundException($file, "translations file $file not found");
+
+    $dictionary = new lmbI18NDictionary();
+
+    if(!$this->_loadFromCache($dictionary, $file))
+    {
+      try
+      {
+        $this->_parseXML($dictionary, file_get_contents($file));
+      }
+      catch(lmbException $e)
+      {
+        throw new lmbException($e->getMessage() . " at file '" . $file . "'");
+      }
+      $this->_saveToCache($dictionary, $file);
+    }
+    return $dictionary;
+  }
+
+  protected function _parseXML($dictionary, $xml)
+  {
+    if(!$xml_doc = simplexml_load_string($xml))
+    {
+      throw new lmbException('SimpleXML parsing error');
+    }
+
+    foreach($xml_doc->context as $context)
+    {
+      foreach($context->message as $message)
+      {
+        if($translation = trim((string)$message->translation))
+          $dictionary->add((string)$message->source, $translation);
+        else
+          $dictionary->add((string)$message->source);
+      }
+    }
+    return true;
+  }
+
+  function saveToFile($file, $dictionary)
+  {
+    $this->getDOMDocument($dictionary)->save($file);
+  }
+
+  protected function _isFileCachingOn()
+  {
+    return $this->use_cache && $this->cache_dir;
+  }
+
+  protected function _loadFromCache($dictionary, $file)
+  {
+    if(!$this->_isFileCachingOn())
+      return false;
+
+    if(!file_exists($cache = $this->_getCacheFile($file)))
+      return false;
+
+    $dictionary->setTranslations(unserialize(file_get_contents($cache)));
+    return true;
+  }
+
+  protected function _saveToCache($dictionary, $file)
+  {
+    if(!$this->_isFileCachingOn())
+      return;
+
+    $cache = $this->_getCacheFile($file);
+    if(!is_dir($dir = dirname($cache)))
+      mkdir($dir);
+    file_put_contents($this->_getCacheFile($file), serialize($dictionary->getTranslations()), LOCK_EX);
+  }
+
+  protected function _getCacheFile($file)
+  {
+    return $this->cache_dir . '/i18n-qt/' . md5(realpath($file));
+  }
+}
+
+



More information about the limb-svn mailing list