------------------------------------------------------------
revno: 931
committer: Roger Martin <[email protected]>
branch nick: aikiframework
timestamp: Fri 2011-11-11 21:22:06 +0100
message:
  translation in widget
modified:
  src/bootstrap.php*
  src/libs/classes/dictionaryTableClass.php
  src/libs/dictionary.php
  src/libs/site.php*
  src/libs/widgets.php


--
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/bootstrap.php' (properties changed: +x to -x)
--- src/bootstrap.php	2011-11-08 13:42:45 +0000
+++ src/bootstrap.php	2011-11-11 20:22:06 +0000
@@ -95,6 +95,7 @@
 	
 /** Instantiate a new log for global use
  * @global Log $log */
+  
 $log = new Log($config["log_dir"],
 			$config["log_file"],
 			$config["log_level"],
@@ -141,7 +142,6 @@
 $aiki->load("message");
 $aiki->load("dictionary");
 
-
 /**
  * Load basic class: site, membership (permission), language, url(user requests)
  * @global membership $membership
@@ -152,20 +152,11 @@
 $aiki->load('site'); 
 $aiki->load('config');
 
+$aiki->load("languages");
+
 $membership = $aiki->load("membership");
 
 
-
-$aiki->load("languages");
-
-if ( $aiki->site->language() != "en" ) {
-	include_once ("$AIKI_ROOT_DIR/libs/classes/dictionaryTableClass.php");
-	$aiki->dictionary->add("core", new dictionaryTable($aiki->site->language()));
-}
-
-
-
-
 // this class will be loaded by demand 
 /*
 $aiki->load("text");

=== modified file 'src/libs/classes/dictionaryTableClass.php'
--- src/libs/classes/dictionaryTableClass.php	2011-11-10 21:42:11 +0000
+++ src/libs/classes/dictionaryTableClass.php	2011-11-11 20:22:06 +0000
@@ -28,14 +28,14 @@
    * 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)
+   * @param $table where terms are stored (optional, aiki_dictionaries by default)  
    *
-   * Exampless $diccio = new ( "eu", "plugins_diccio");
+   * @Examples: $diccio = new ( "eu", "en", "plugins_diccio");
    *
    */
 
-  function __construct( $to, $table="aiki_dictionaries", $from="en" ) {
+  function __construct( $to, $from="en", $table="aiki_dictionaries"  ) {
     $this->table= $table;
     $this->to   = $to;
     $this->from = $from;

=== modified file 'src/libs/dictionary.php'
--- src/libs/dictionary.php	2011-11-10 21:42:11 +0000
+++ src/libs/dictionary.php	2011-11-11 20:22:06 +0000
@@ -20,7 +20,7 @@
 	die('No direct script access allowed');
 }
 
-
+include_once ("$AIKI_ROOT_DIR/libs/classes/dictionaryTableClass.php");
 
 class Dictionary {
 	private $tranlateTo;
@@ -30,12 +30,14 @@
 	private $domains;
 
 	function __construct(){
+		global $aiki;		
 		$this->noDomains = true;
 		$this->domains = array();
 		$this->translateFrom = "en";
-		$this->translateTo = "en";
+		$this->translateTo   = "en";
 	}
 	
+	
 	/**
 	 * Add a new domain to Dictionary store.
 	 * 
@@ -204,5 +206,9 @@
 	if (!$aiki->site->need_translation()) {
 		return $term;
 	}
-	return $aikiDictionary->translate($term, $config["translateFrom"], $config["translateTo"], $domain);
+	return $aiki->dictionary->translate(
+		$term, 
+		$aiki->dictionary->translateFrom(), 
+		$aiki->dictionary->translateTo(), 
+		$domain);
 }

=== modified file 'src/libs/site.php' (properties changed: +x to -x)
--- src/libs/site.php	2011-11-08 13:42:45 +0000
+++ src/libs/site.php	2011-11-11 20:22:06 +0000
@@ -32,6 +32,7 @@
 	private $languages; // a array like [0]=>'en',[1]=>'fr'...
 	private $need_translation;
 	private $default_language;
+	private $widget_language;
 	private $site_prefix; 
 	private $site_view;
 	private $site_view_prefix;
@@ -70,8 +71,9 @@
 	 * @return array languages
 	 */	  
 	function language($new=NULL) {		
+		global $aiki;
 		if (!is_null($new)) {
-			if (in_array($new, $this->languages)) {
+			if (in_array($new, $this->languages)) {	
 				$this->default_language = $new;
 				$this->need_translation = ($new != $this->widget_language);
 				return true;				
@@ -109,15 +111,13 @@
 	}
 
 	/**
-	 * return true if site content (generated by widget) need to be 
-	 * translated
+	 * return true if site need to be translated
 	 * @return boolean
 	 */
 	function need_translation() {
 		return $this->need_translation;
 	}
 
-
 	/**
 	 * magic method for use object site as a string
 	 * @return string Return site long name
@@ -168,7 +168,7 @@
 					  	"ENABLE_RUNTIME_INSTALLER is set to FALSE." : ""),
 				NULL, false));	  
 		} elseif ( $info->is_active != 1 ) {
-			die($aiki->messgae->error($info->if_closed_output ? $info->if_closed_output : "Site {$config['site']} is closed.",
+			die($aiki->message->error($info->if_closed_output ? $info->if_closed_output : "Site {$config['site']} is closed.",
 				NULL,
 				false));
 		}
@@ -208,14 +208,25 @@
 		if (isset($_GET['language'])) {			
 			$this->language(addslashes($_GET['language']));
 		} elseif ($this->language($aiki->url->first_url())) {
-			$aiki->url->shift_url();
+			$aiki->url->shift_url();			
 		}
 		$this->need_translation = ($this->default_language != $this->widget_language);
-				
+
+		//  the site manages dictionaries		
+		if ( $this->default_language != "en" ) {
+			$aiki->dictionary->add("core", new dictionaryTable($this->default_language));
+			$aiki->dictionary->translateTo($this->default_language);
+		}			
+		
+		if ( $this->widget_language != "en" ) {
+			$aiki->dictionary->translateFrom($this->widget_language);
+			$aiki->dictionary->add($config['site'], new dictionaryTable($this->default_language,$this->widget_language));
+		}	
+
 		// site names
 		$this->site = $config['site'];
 		$this->site_name = $info->site_name;
 	}
 }
 
-?>
\ No newline at end of file
+?>

=== modified file 'src/libs/widgets.php'
--- src/libs/widgets.php	2011-11-08 13:42:45 +0000
+++ src/libs/widgets.php	2011-11-11 20:22:06 +0000
@@ -526,6 +526,11 @@
 			$processed_widget = $aiki->Forms->displayForms($processed_widget);
 			$processed_widget = $aiki->input->requests($processed_widget);
 			$processed_widget = $aiki->php->parser($processed_widget);
+			
+			$processed_widget = $this->parse_translate_widget($processed_widget);
+			$processed_widget = $this->parse_translate_aiki_core($processed_widget);
+			
+			
 			$processed_widget = stripslashes($processed_widget);
 		}
 		
@@ -940,7 +945,51 @@
 		return $text;
 	}
 
-
+	/**
+	 * Proccesed all (t(text_to_translate)t) .
+	 *
+	 * @PARA  string $widget_content to be translated
+	 * @RETUN string widget translated
+	 */
+
+
+	function parse_translate_widget(&$widgetContents) {				
+	global $aiki;		
+		if (!$aiki->site->need_translation()) {	
+			return preg_replace('/\(t\((.*)\)t\)/Us','$1', $widgetContents);
+		} else {				
+			return preg_replace_callback(
+				'/\(t\((.*)\)t\)/Us',
+				create_function(
+					'$matches',
+					'return t($matches[1]);')
+				,$widgetContents );
+		}		
+	}
+	
+	/**
+	 * Proccesed all (__(text_to_translate)__) .
+	 *
+	 * @PARA  string $widget_content to be translated
+	 * @RETUN string widget translated
+	 */
+
+
+	function parse_translate_aiki_core(&$widgetContents) {				
+	global $aiki;		
+		if ($aiki->site->language()=="en") {	
+			return preg_replace('/\(__\((.*)\)__\)/Us','$1', $widgetContents);
+		} else {					
+			return preg_replace_callback(
+				'/\(__\((.*)\)__\)/Us',
+				create_function(
+					'$matches',
+					'return __($matches[1]);')
+				,$widgetContents );
+		}		
+	}
+	
+	
 	/**
 	 * Proccesed all (#(hits:..)#) in widget content.
 	 *
@@ -1205,4 +1254,4 @@
 
 } // end of CreateLayout Class
 
-?>
\ No newline at end of file
+?>

_______________________________________________
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