Ei18n Translation Module

I have just released a translation module: Ei18n.

Description

Ei18 is a translation module to allow Yii’ers to easily manage missing translations on application pages. It is heavily inspired by yii.translate developed by Gustavo Salomé Silva gusnips.


Please use this forum thread for bugs, feedback, improvements, etc…

Extension link on Yii repository: http://www.yiiframework.com/extension/ei18n/


Hope you find it as useful as it is for me…

Cheers

Thanx Antonio for sharing. It looks very interesting.

I’ve just downloaded it and went to download the requirements, and found that Fancybox is “Now licensed under Creative Commons Attribution-NonCommercial 3.0” :frowning:

So I guess if I want to use it, I should change it by CJuiDialog. What do you think?

I made use of Fancybox in order to make the module a bit nicer and thinking that as the task to manage translations are on development states (once all translations are done, is up to the backend to update them) the license wont affect it… but changing the module to CJuiDialog shouldn’t be a hard task.

hi guys,

i wonder the line


'onMissingTranslation' => array('Ei18n', 'missingTranslation'),

will cause my page become blanks, but it become ok when remove this line. Anyone know what cause this problem happens??


   

/* import the module */

   'import'=>array(

   /* ... */

       'application.modules.translate.TranslateModule',

 'components' => array(

        'messages' => array(

            'class' => 'CDbMessageSource',

            'onMissingTranslation' => array('Ei18n', 'missingTranslation'),    <---- this line

            'sourceMessageTable' => 'tbl_source_message',

            'translatedMessageTable' => 'tbl_message'

        ),

        /* setup global translate application component */

        'translate' => array(

            'class' => 'translate.components.Ei18n',

            'createTranslationTables' => true,

            'connectionID' => 'db',

            'languages' => array(

                'en' => 'English',

                'es' => 'Español',

                'it' => 'Italiano'

            )

        ),

/* setup the module */

       'modules' => array(

            'translate'

        ),

/* preload the global translate application component */

       'preload'=> array(

            'translate'

        )

thanks guys.

What that line says is that onMissingTranslation, the component should call Ei18n, have you preloaded the component? Check installation instructions.

hi Antonio Ramirez,

i follow the configuration Ei18n,unzip the file and copy the translate folder inside protected/modules. then

copy


Yii::app()->translate->renderMissingTranslationsEditor();

to column2 in layouts. The config main also follow to ei18n. The problem still happens!!

Pls helps. Thanks

Hi, its all working fine with the translations, the only problem I got is that when I make one ajax call rendering its return on a jQuery dialog, the translator doesn’t recognize the new translations.

Is there a way to make it do that?


CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax  error or access violation: 1064 You have an error in your SQL syntax;  check the manual that corresponds to your MySQL server version for the  right syntax to use near 'TYPE=InnoDB' at line 7. The SQL statement  executed was: 

				CREATE TABLE tbl_source_message

				(

					id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,

					category VARCHAR(32) NOT NULL,

					message TEXT

 

				)TYPE=InnoDB   	

What is the problem?

I create those tables manually but now getting this error when go to http://localhost/index.php?r=translate/:




      

[b]Error 404[/b]

  The system is unable to find the requested action "index".



[size="5"]Can anyone describes about usage of this extension?[/size]

I made a little adjustment to the module to also be able to use this in AJAX requests. There are probably better ways to do this but it got the job done for me.

in WTranslate.php (under Widgets) replace the function registerScripts with :




public function registerScripts()

	{

		$translations = function_exists('json_encode') ? json_encode($this->translations) : CJSON::encode($this->translations);

		if(!Yii::app()->request->isAjaxRequest ) 

		{

		$js = <<<EOD

		var wtranslate = (function($){

			var open = false;

			var l = null;

			var t = {$translations};

			var pub = {

				msg: function(o){

					if(jbar) {jbar.open(o);}

				},

				add: function(col, obj){

					var li = $('<li/>').addClass('item');

					if (obj.new == 'yes')

						var div = $('<div/>').text(obj.text);

					else

						var div = $('<div/>').text(obj.text).addClass('edited');

						

					var a = $('<a/>',{class: 'wtranslate fancybox.ajax', id:'wt-'+obj.ref, href: obj.url}).text('edit');

					

					var span = $('<span/>').append(a);

					div.append(span);

					li.append(div);

				

					$('ul',col).append(li);

					col.show();

				},

				update: function (f) 

				{

					var data = f.serialize();

					$.ajax({

						url: f.attr('action'),

						data: data,

						dataType: 'json',

						type: 'post',

						success: function(d){

							if(typeof d == 'object')

							{

								var a = $('#wt-'+d.id);

								if(a.length){

									a.closest('div').addClass('edited');

								}

								jbar.open(d);

							}

						}

					});

					$.fancybox.close();

				},

				buildLinks: function() {

					var cnt = 1;

					for(i=0; i<t.length; i++)

					{

						

						this.add($('.col'+cnt, l), t[i]);

						if(++cnt > 3) {cnt = 1;}

					}

				},

				buildSlider: function(){

					l = $('<div/>').attr('id','wtranslator-footerSlideContainer');

					var button = $('<div/>').attr('id','wtranslator-footerSlideButton');

					var content = $('<div/>').attr('id','wtranslator-footerSlideContent');

					var text = $('<div/>').attr('id','wtranslator-footerSlideText');

					text.html("\

					<h3>{$this->title}</h3>\

					<div id='one-true'>\

						<div class='col col1'><ul></ul></div>\

						<div class='col col2'><ul></ul></div>\

						<div class='col col3'><ul></ul></div>\

					</div>");

					content.append(text);

					l.append(button,content);

					$('body').append(l);

				},

				init: function(){

					//if( !t.length ) return; /* no missing translations? what do you wish to do?*/

					this.buildSlider();

					this.buildLinks();

					$(".wtranslate").fancybox({

						width	: 800,

						height	: 600,

						minWidth	: 800,

						fitToView	: false,

						autoSize	: false,

						closeClick	: false,

						openEffect	: 'none',

						closeEffect	: 'none',

						topRatio    : 0,

						afterShow	: function(){

							$('.wtranslate-wysiwyg').wysiwyg({initialContent:''});

							$(".fancybox-wrap").css({"top":0, "margin":"100px 0 0"});

						}

					});

					jQuery('.fancybox-wrap').css('margin-top', '120px');

					$('#wtranslator-footerSlideButton').on('click',function(){

						var content = $('#wtranslator-footerSlideContent');

						var w = $('#wtranslator-footerSlideText').height() + 50;

						if(content.is(':animated'))

							return false;


						if(content.hasClass('footerSlideVisible')){

							content.animate({ height: '0px' }).removeClass('footerSlideVisible').addClass('footerSlideHidden');

							$(this).css('backgroundPosition', 'top left');

						}

						else {

							content.animate({ height: w+'px' }).removeClass('footerSlideHidden').addClass('footerSlideVisible');

							$(this).css('backgroundPosition', 'bottom left');

						}

						return false;

					});

					$(document).on('click', '.translate-buttons > a', function() {

						var action = $(this).attr('rel');

						if(action=='submit')

						{

							var frm = $('.translate-form > form');

							wtranslate.update(frm);

						}

						else if(action=='close')

						{

							$.fancybox.close();

						}

						return false;

					});

				}

			};

			

			return pub;

			

		})(jQuery);

EOD;

		$assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . '/assets');


		$cs = Yii::app()->clientScript;

		

		/* widget js files */

		$cs->registerCoreScript('jquery');

		$cs->registerScript(__CLASS__ . 'EndJS', $js, CClientScript::POS_END);


		/* fancybox files */

		$cs->registerCssFile($assets . '/fancybox/source/jquery.fancybox.css');

		$cs->registerScriptFile($assets . '/fancybox/source/jquery.fancybox.pack.js', CClientScript::POS_END);


		/* jwysiwyg files */

		$cs->registerCssFile($assets . '/jwysiwyg/jquery.wysiwyg.css');

		$cs->registerScriptFile($assets . '/jwysiwyg/jquery.wysiwyg.js', CClientScript::POS_END);

		$cs->registerScriptFile($assets . '/jwysiwyg/controls/wysiwyg.link.js', CClientScript::POS_END);

		$cs->registerScriptFile($assets . '/jwysiwyg/controls/wysiwyg.table.js', CClientScript::POS_END);


		/* modified jbar files */

		$cs->registerCssFile($assets . '/jbar/css/jbar.style.css');

		$cs->registerScriptFile($assets . '/jbar/jquery.bar.js', CClientScript::POS_END);




		/* widget style files */

		$cs->registerCssFile($assets . '/wtranslator.style.css');


		/* init the module on document ready */

		$cs->registerScript('WTranslateReadyJS', 'wtranslate.init();', CClientScript::POS_READY);

		

		}

		else

		{

			

		$js = <<<EOD

			var t = {$translations};

			var l = null;

			function add(col, obj){

				var li = $('<li/>').addClass('item');

				if (obj.new == 'yes')

					var div = $('<div/>').text(obj.text);

				else

					var div = $('<div/>').text(obj.text).addClass('edited');

					

				var a = $('<a/>',{class: 'wtranslate fancybox.ajax', id:'wt-'+obj.ref, href: obj.url}).text('edit');

				

				var span = $('<span/>').append(a);

				div.append(span);

				li.append(div);

				$('ul',col).append(li);

				col.show();

			}

			

			function buildLinks() {

				var cnt = 1;

				for(i=0; i<t.length; i++)

				{

					

					this.add($('.col'+cnt, l), t[i]);

					if(++cnt > 3) {cnt = 1;}

				}

			}

			

			buildLinks();

EOD;

		}

		$cs = Yii::app()->clientScript;

		$cs->registerScript(__CLASS__ . 'EndJS', $js, CClientScript::POS_END);

	}



And put this in every partial view rendered by Ajax:




echo Yii::app()->translate->renderMissingTranslationsEditor();



Hope this helps!