4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: Lucifix on January 28, 2009, 09:44:11 PM

Title: [MOD] Google AJAX Translation / Without Page reload
Post by: Lucifix on January 28, 2009, 09:44:11 PM
Original MOD writen for Wordpress by Libin Pan and Michael Klein:
http://wordpress.org/extend/plugins/google-ajax-translation/

Description:
This MOD will translate comment to chosen language.

Demo:
http://www.slo-foto.net/galerija_slika-45687.html

Screenshot:
(http://img204.imageshack.us/img204/8448/ajaxcommentsho7.jpg) (http://imageshack.us)

How to do it?
1.
- open templates/[your template folder]/comment_bit.html
- search:
Code: [Select]
{comment_text}
- replace with:
Code: [Select]
<div id="translate_comment_{comment_id}">{comment_text}</div>
2.
- search:
Code: [Select]
{comment_user_icq_button}
Use A (for text) or B (with images)
- A: after add (text):
Code: [Select]
<p>View this Comment in: <a href="javascript:google_translate('en','comment',{comment_id});">English</a> <a href="javascript:google_translate('de','comment',{comment_id});">Deutsch</a> <a href="javascript:google_translate('fr','comment',{comment_id});">French</a></p>
- B: after add (images)
Code: [Select]
<p>View this Comment in: <a href="javascript:google_translate('en','comment',{comment_id});"><img src="{template_url}/images/gb.png" border="0"></a> <a href="javascript:google_translate('de','comment',{comment_id});"><img src="{template_url}/images/de.png" border="0"></a> <a href="javascript:google_translate('fr','comment',{comment_id});"><img src="{template_url}/images/fr.png" border="0"></a></p>- (only if you use B for images) download flags.zip file and upload content to folder:templates/[your template folder]/images/

3.
- open templates/[your template folder]/footer.html

- search:
Code: [Select]
</body>
- before add:
Code: [Select]
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load('language', '1');
    var original_posts = new Array();
    var original_comments = new Array();
    function google_translate(lang, type, id){
      text_node = document.getElementById('translate_'+type+'_'+id);
      original_text = get_original_text(type, id, text_node);
      to_translate_text = original_text.replace(/<\/?[^>]*>/g, '');
      to_append_text = '';
      if (to_translate_text.length > 500)
        to_append_text = to_translate_text.substr(500);
      to_translate_text = to_translate_text.substr(0, 500);
      google.language.detect(to_translate_text, function(result) {
        if (!result.error && result.language) {
          google.language.translate(to_translate_text, result.language, lang, function(result) {
            if (!result.error)
              text_node.innerHTML = result.translation + to_append_text;
            else
              text_node.innerHTML = original_text;
          });
        }
      });
    }

    function get_original_text(type, id, text_node) {
      switch(type) {
        case 'post':
          original_text = original_posts[id];
          if (original_text == null)
            original_text = original_posts[id] = text_node.innerHTML;
          break;
        case 'comment':
          original_text = original_comments[id];
          if (original_text == null)
            original_text = original_comments[id] = text_node.innerHTML;
          break;
      }
      return original_text;
    }
    function google_translate_callback() {}
    google.setOnLoadCallback(google_translate_callback);
</script>

That's it! Enjoy!  :wink:
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: mawenzi on January 28, 2009, 10:25:42 PM
... it looks very nice on your site ...
... and thanks for sharing ...
... move to "Mods & Plugins (Releases & Support)" ...
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: mawenzi on January 31, 2009, 06:58:02 PM
hey Lucifix ...

... only one word to this modification ... PERFECT ...  :D
... it works now in the best way on my website ...
... thanks again for sharing ...
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: Lucifix on January 31, 2009, 07:11:38 PM
Glad you like it!  :wink:
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: om6acw on January 31, 2009, 10:55:43 PM
great mod  :!:
congratulation  :!: :!: :!:
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: om6acw on February 01, 2009, 03:50:29 PM
Somehow I can't see the flags in my comments (http://www.myanimalsworld.com/img_castle_mountain_89.htm (http://www.myanimalsworld.com/img_castle_mountain_89.htm)), should I put them on my server? or they are located on google site? thanks for reply.
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: V@no on February 01, 2009, 06:07:43 PM
Flags are not part of the mod ;) You'll need add them manually.
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: om6acw on February 01, 2009, 06:24:58 PM
Flags are not part of the mod ;) You'll need add them manually.

Ok V@no, i see. Then in this case demo pic should be added without the flags ;) its misleading.
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: Lucifix on February 01, 2009, 06:34:42 PM
Flags are not part of the mod ;) You'll need add them manually.

Ok V@no, i see. Then in this case demo pic should be added without the flags ;) its misleading.

Okey I added version for images... but next time check some tutorials how replace text with images before you make complain: ;)
http://www.w3schools.com/htmL/html_images.asp
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: om6acw on February 01, 2009, 06:53:39 PM
Flags are not part of the mod ;) You'll need add them manually.

Ok V@no, i see. Then in this case demo pic should be added without the flags ;) its misleading.

Okey I added version for images... but next time check some tutorials how replace text with images before you make complain: ;)
http://www.w3schools.com/htmL/html_images.asp

no hard feelings my friend, but you are presenting mod with demo page and screen shots, I'm expecting some look after installation on my site, if something what's on your demo information's are not part of the mod you have to mentioned that in installation instructions otherwise you will hear complains.
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: Lucifix on February 01, 2009, 06:58:27 PM
No hard feelings taken. What bothers me that people ask without trying something by their self.
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: om6acw on February 01, 2009, 07:08:49 PM
No hard feelings taken. What bothers me that people ask without trying something by their self.

Its not problem for me put images there, but I was expecting them to be there automatically because I saw your demo page and screen shot, That's the reason why I was asking about them.
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: sanko86 on February 03, 2009, 03:24:40 PM
thank you @Lucifix

good mod

ý mod use the my site: www.elemegim.info
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: mzawdi on February 20, 2009, 04:07:15 AM
haw add another language
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: V@nо on February 20, 2009, 04:16:00 AM
Welcome to 4images forum.

Edit code from step 2.
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: moto1985 on March 27, 2009, 12:43:02 AM
kann man diesen mod auch für eine Komplette seite verwenden?
oder nur für Kommentare?
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: mawenzi on March 27, 2009, 01:29:55 AM
@ moto1985

1. vom Standard her ist das Script für die Übersetzung von max. 500 Zeichen ausgelegt ...
2. sämtliche html- / bb-Formatierungen zwischen <div id="translate_comment_{comment_id}"> und </div> gehen mit der Übersetzung verloren ...
   
... ergo ...
... damit eignet sich das Script tatsächlich nur für Kommentare / Beschreibungen / Statements innerhalb einer html-Formatierung (z.B. einer Tabellenzelle) ...
... bei einer kompletten Seite siehst du nach der Übersetzung nur noch unformatierten Text, ohne Bilder, Tabellen u.d.gl. ...
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: AntiNSA2 on April 01, 2009, 01:17:50 PM
Is it possible to get this mod to work for image description?
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: AntiNSA2 on April 01, 2009, 01:22:48 PM
HAs anyone gotten this to work together with ajax show comments without page reload/ comments rating mod?
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: mawenzi on April 01, 2009, 01:31:29 PM
... the Google translation works also for image description if it is no longer than 500 characters ...
... you can also test it with e.g. 1000 characters ... then replace all "500" with "1000" in the javascript ...
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: AntiNSA2 on April 01, 2009, 02:55:39 PM
Ok, I will try it.... but how to change the variables in the Javascript to make it work with

{image_description}
and {image_keywords} ?


I know these things must be changed :

 var original_posts = new Array();
    var original_comments = new Array();

And some others I think... but I dont know how to change them.. what to change them to.



If this mod could be made to work with V@nos multiple Language MOD (version b) that would even be super cool. If not it is ok to see the little flags by the keywords and image description.

I can say this mod DOES Work with the Ajax image comment/rating mod...
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: AntiNSA2 on April 01, 2009, 03:05:09 PM
After following the directions to try to get this to work with latest comments on front page mod by V@no... I can say it does not work when adding the code to the last_comment.html template......

I will post to that thread to ask for help......
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: bergblume on July 09, 2009, 09:30:55 AM
... the Google translation works also for image description if it is no longer than 500 characters ...
... you can also test it with e.g. 1000 characters ... then replace all "500" with "1000" in the javascript ...

hi mawenzi,

can you pls. give me a detailed explanation how to get it worl with image description --- which files how to modify?

thank you, bergblume
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: mawenzi on July 16, 2009, 07:50:36 PM
@bergblume

... in details.html verwende statt ...
Code: [Select]
{image_description}

... nun dieses ...
Code: [Select]
<div id="translate_comment_{image_id}">{image_description}</div><br>
<div align="right"><small>Bild-Beschreibung in: <a href="javascript:google_translate('en','comment','{image_id}');" title="Description in English">
<img src="{template_url}/images/gb.gif" border="0"></a>&nbsp;<a href="javascript:google_translate('de','comment','{image_id}');" title="Beschreibung in Deutsch">
<img src="{template_url}/images/de.gif" border="0"></a>&nbsp;<a href="javascript:google_translate('fr','comment','{image_id}');" title="Description en Français">
<img src="{template_url}/images/fr.gif" border="0"></a></div>

... vorausgesetzt, dass die Modifikation bereits für die Kommentare installiert ist, so braucht das J-Script nicht nochmals eingebunden werden ...
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: rinaldos on July 16, 2009, 09:52:53 PM
@mawenzi,
das war ja einfach :-) KLappt wunderbar. Danke dir für das Addon :-)

LG
Ingo
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: Frank Götze on November 09, 2009, 08:59:02 AM
Danke für den MOD Lucifix,

@mawenzi & rinaldos,

das klappt ja wunderbar mit der Description. Um die Sache abzurunden fehlen nun noch aus meiner Sicht zwei Varianten. Die Umsetzung für deinen [MOD] All Comments (Alle Kommentare) V.1.6 und für den [MOD] Last comments v1.2.0 . Hier habe ich ein Problem mit der Image ID für den jeweiligen Kommentar. :oops: Habt ihr dafür einen Ansatz? Zumindest habe ich es auf euren Seiten gesehen, also müsste es ja da auch gehen.

VG Frank.
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: mawenzi on November 09, 2009, 08:00:35 PM
Hallo Frank,

... du brauchst für die Zuweisung immer eine Eindeutige ID und die kann bei den Kommentaren nicht die image_id sein ... logisch, denk ich ...
... bei den jeweiligen Kommentar-Listen verwende ich also zur Auswahl des Kommentars nicht die image_id, sondern die comment_id ...
... das sieht dann für [MOD] All Comments (Alle Kommentare) V.1.6 in der comments_all_bit.html z.B. wie folgt aus ...

Code: [Select]
<div id="translate_comment_{comment_id}">{comment_text}</div>
<div align="right"><small>Kommentar in: <a href="javascript:google_translate('en','comment',{comment_id});" title="Comment in English">English</a>
<a href="javascript:google_translate('de','comment',{comment_id});" title="Kommentrar in Deutsch">Deutsch</a>
<a href="javascript:google_translate('fr','comment',{comment_id});" title="Commentaires en Français">French</a>

... in der comments_all.php finde ...
Code: [Select]
"total_image_comments" => $total_image_comments,
... und füge dahinter noch ein ...
Code: [Select]
"comment_id" => $comment_row[$i]['comment_id'],

... bei Erfolg bitte kurzes Statement ... danke ...
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: Frank Götze on November 09, 2009, 10:55:29 PM
Guten Abend mawenzi,

danke für die Hilfestellung!  :thumbup:  Jetzt funktioniert der MOD ebenfalls ohne Beanstandungen in deinem  [MOD] All Comments (Alle Kommentare) V.1.6 .

LG Frank.
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: zakaria666 on August 29, 2010, 05:18:10 PM
How do i add new langauges. Ive tried Vanos ways of just editing step 2 but for example if i want danish then all i change is the fr to dn but it wont work.

pleasee thank u guys
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: V@no on August 29, 2010, 08:18:49 PM
danish = da , not dn
http://code.google.com/apis/ajaxlanguage/documentation/reference.html#LangNameArray
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: Loda on December 22, 2011, 10:16:58 PM
hello,
i don't know, but i think that google has delete the translation..
anybody else here who can confirm that?
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: alekseyn1 on December 28, 2011, 02:53:52 PM
hello,
i don't know, but i think that google has delete the translation..
anybody else here who can confirm that?

I confirm... this does not work any more... looking for another solution

this is official message from Google:

Important: Google Translate API v1 was officially deprecated on May 26, 2011; it was shut off completely on December 1, 2011. For text translations, you can use the Google Translate API v2, which is now available as a paid service. For website translations, we encourage you to use the Google Website Translator gadget.
Title: Re: [MOD] Google AJAX Translation / Without Page reload
Post by: Lucifix on January 17, 2012, 01:23:47 PM
Since Google has deprecated translation API (it's not free anymore), maybe we should start using Bing Translation API:
http://msdn.microsoft.com/en-us/library/ff512406.aspx

Maybe if I'll find time I try to integrate this in 4homepages gallery, but I cannot give you any hope ;)