Merge authors:
  rg1024 (rg1024)
------------------------------------------------------------
revno: 930 [merge]
committer: Bassel Safadi <[email protected]>
branch nick: aikiframework
timestamp: Fri 2011-11-11 10:58:43 +0200
message:
  clean up and merge with my previous commit this should not break anything
modified:
  src/libs/classes/dictionaryTableClass.php
  src/libs/dictionary.php*
  src/sql/CreateTables.sql


--
lp:aikiframework
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk

Your team Aiki Framework Developers is subscribed to branch lp:aikiframework.
To unsubscribe from this branch go to 
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk/+edit-subscription
=== modified file 'src/libs/classes/dictionaryTableClass.php'
--- src/libs/classes/dictionaryTableClass.php	2011-11-08 13:42:45 +0000
+++ src/libs/classes/dictionaryTableClass.php	2011-11-10 21:42:11 +0000
@@ -15,7 +15,7 @@
  * @category    Aiki
  * @package     Library
  *
- * Implementation of a dictionary using arrays.
+ * Implementation of a dictionary using tables.
  *
  *
  */
@@ -23,7 +23,18 @@
 
 class DictionaryTable{
   private $table, $to, $from, $fake;
-  
+
+  /**
+   * Construct a dictionary.
+   * 
+   * @param $to language to translate
+   * @param $table where terms are stored (optional, aiki_dictionaries by default)
+   * @param $from language from translate (optional, "en" by default)
+   *
+   * Exampless $diccio = new ( "eu", "plugins_diccio");
+   *
+   */
+
   function __construct( $to, $table="aiki_dictionaries", $from="en" ) {
     $this->table= $table;
     $this->to   = $to;
@@ -33,14 +44,22 @@
   
   function search($term){
     global $db;    
+    $search = addslashes($term);
     $SQL = 
         "SELECT translation FROM ". $this->table .
-        " WHERE term='$term'".
+        " WHERE term='$search'".
         "  AND translateto='{$this->to}' AND translatefrom = '{$this->from}'";
     $found= $db->get_var($SQL);
     return ( is_null($found) ? false : $found );
   }
   
+  /**
+   * translate given term
+   * 
+   * @param $term to translate
+   * @return string term translated (if necesary)   
+   */  
+  
   function translate($term){
     if ($this->fake){
         return $term;
@@ -49,10 +68,22 @@
     return ( $founded===false ? $term : $founded);
   }
   
+  /**
+   * return language which terms will be translated 
+   * 
+   * @return string original language   
+   */  
+  
   function translateTo(){
     return $this->to;
   }
   
+  /**
+   * return original language of terms 
+   * 
+   * @return string original language   
+   */    
+  
   function translateFrom(){
     return $this->from;
   }

=== modified file 'src/libs/dictionary.php' (properties changed: +x to -x)
--- src/libs/dictionary.php	2011-11-08 13:42:45 +0000
+++ src/libs/dictionary.php	2011-11-10 21:42:11 +0000
@@ -36,6 +36,16 @@
 		$this->translateTo = "en";
 	}
 	
+	/**
+	 * Add a new domain to Dictionary store.
+	 * 
+	 * A domain is a dictionary object that translate terms from certain language to other.
+	 * 
+	 * @param string domain name
+	 * @param dictionary $dictionary object
+	 * 
+	 */
+	
 	function add($domain,$dictionary){		
 		$to   = $dictionary->translateTo();
 		$from = $dictionary->translateFrom();
@@ -52,6 +62,14 @@
 		$this->noDomains = false; 
 	}
  
+	/**
+	 * set/get default domain
+	 * 
+	 * @param string (optional) new default domain
+	 * @return string actual domain or if given, return previus.
+	 * 
+	 */
+
 	function domain($new=NULL){
 		$ret = $this->defaultDomain;
 		if (!is_null($new)) {
@@ -60,6 +78,14 @@
 		return $ret;
 	}
 	
+	/**
+	 * set/get default target language (to be translated)
+	 * 
+	 * @param string (optional) new language
+	 * @return string actual target language or if given, return previous.
+	 * 
+	 */
+	
 	function translateTo($new=NULL){
 		$ret = $this->translateTo;
 		if (!is_null($new)) {
@@ -68,6 +94,14 @@
 		return $ret;
 	}
 	
+	/**
+	 * set/get original language
+	 * 
+	 * @param string (optional) new default language
+	 * @return string actual language or if given, return previous.
+	 * 
+	 */
+	
 	function translateFrom($new=NULL){
 		$ret = $this->translateFrom;
 		if (!is_null($new)) {
@@ -76,6 +110,18 @@
 		return $ret;
 	}
 	
+	
+	/**
+	 * translate a term
+	 * 
+	 * @param $term to be translated
+	 * @param $translateFrom (optional), target language.
+	 * @param $translateTo (optional), term language.
+	 * @param $domain(optional), domain to be used.
+	 * @return string term translated
+	 * 
+	 */
+	
 	function translate( $term, $translateFrom=NULL, $translateTo=NULL, $domain=NULL){	
 		$to = is_null($translateTo) ? $this->translateTo : $translateTo;
 		$from = is_null($translateFrom)? $this->translateFrom : $translateFrom;
@@ -95,10 +141,15 @@
 	}
 }
 
-/*
- * Shortcut for use in aiki code, apps, extension and libs
- * Note: aiki is develop in english, and 'core' is the default dictionary.
- **************************************/
+/**
+ * Shortcut for use in aiki code, apps, extension and libs to translate a term
+ *
+ * Aiki is develop in english, and 'core' is the default dictionary.
+ * 
+ * @param string $term to be translated
+ * @param string $domain (optional, "core" by default)
+ * 
+ */
 
 function __($term, $domain=NULL){	
 	global $aiki;
@@ -113,9 +164,12 @@
 }
 
 
-/*
- * Shortcut for use in aiki code, apps, extension and libs
- * Note: there is not  domain parameter 
+/**
+ * Shortcut for sprintf with translation
+ *
+ * @param string arg1 string formatted as sprinft
+ * @param mixed rest
+ * 
  **************************************/
 
 function __sprintf (){	
@@ -133,9 +187,16 @@
 
 
 
-/*
- * Shortcut for use in widget..(need a parser)
- * In this case, base language (translate from) can be any language
+/**
+ * translation of a term.
+ * 
+ * __() functions assumes "en" as original language, t() doesn't.
+ *
+ * 
+ * @param string $term to be translated
+ * @param string $domain (optional, "core" by default)
+ *
+ * 
  **************************************/
 
 function t($term, $domain=NULL){	

=== modified file 'src/sql/CreateTables.sql'
--- src/sql/CreateTables.sql	2011-11-08 13:42:45 +0000
+++ src/sql/CreateTables.sql	2011-11-10 21:42:11 +0000
@@ -149,7 +149,7 @@
   translatefrom varchar(5) NOT NULL,
   translateto varchar(5) NOT NULL,
   translation varchar(120) NOT NULL,
-  PRIMARY KEY (term),
+  KEY term (term),
   KEY translatefrom (translatefrom),
   KEY translateto (translateto)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

_______________________________________________
Mailing list: https://launchpad.net/~aikiframework-devel
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~aikiframework-devel
More help   : https://help.launchpad.net/ListHelp

Reply via email to