I thought it would be nice and helpful addition if we could integrate automatic translation suggestions through the Google AJAX Language API.

The work is pretty much done and feedback would be appreciated. If all this passes scrutiny, I'll port to D6.

  • added admin configuration area to allow enabling/disabling if translation suggestions
  • extended the jQuery code to fetch a translation
  • added current locale setting to the Drupal.settings js object
  • added boolean of whether or not to use translation suggestions to the Drupal.settings js object
  • added a button to copy the suggested translation to the translation textarea
  • made minor changes to the html of the "source" area to allow that either source or translation suggestion is copied to the translation textarea
  • made minor UI change (html) to separate source text from suggested translation
  • made minor css change to separate source text from suggested translation
  • made minor css change so .toggle area highlights on hover
  • fixed #237702: Language name not shown in "Translate to" header


jpoesen’s picture

Version:5.x-1.0» 5.x-1.x-dev
683 bytes
2.2 KB
2.51 KB

Correction: previous supplied patches were created against 5.x-1.0. New patches applied against 5.x-1.x-dev

Gábor Hojtsy’s picture

Hm, sounds quite interesting. Some questions / suggestions:

- How would this look on the UI?
- I'd add more descriptions on what the Google Language API usage means (ie. what is shared with Google, comment about the accuracy of their service, etc).
- I am on the fence of whether this should be on or off by default.

Gábor Hojtsy’s picture

Also, please combine patches into one, it is much easier to review. Thanks!

jpoesen’s picture

The UI change is part of the patch already. See attachment.

1. When clicking a string in the left column, the translation is automatically added to the source text you get in the middle column. The two are clearly separated by a blue line and the locale preceeds the translation:

NL: Verzend

2. an extra button 'copy translation' is added to the 3rd column. To avoid conflict with the 'copy source' button, I've wrapped source content and translation suggestion in a unique div to ensure only source or translation is copied to the textarea

About more comments on the Google api itself (privacy, accuracy, etc): where should this be put? Help? Description on the settings form?

Also, I've extracted the code and put it into a proper module (Google AJAX Language API: http://drupal.org/project/glangapi), but I've yet to release a first version. Would you like the client to depend on that module or is it ok for you like this?

Ok, I'll combine the patches.

Gábor Hojtsy’s picture

It might be better to depend on that extra module and automatically turn on this feature in our module if that module is already in place. That would be an optional dependency. In which case we can forget about the settings page.

I imagined disclaimers on the settings page where the user choose to use the Google AJAX Language API, but this only makes sense of course of we handle all in this module.

jpoesen’s picture

Ok to let the client depend on the extra module, but I can imagine that an admin would like to be able to have the translation suggestions enabled site wide (setting in glangapi), while being able to disable it specifically for the client.

I'm thinking of a simple plugin system for glangapi where one or more additional modules would provide integration with (and a settings interface for) modules like the localization client.

If we want to enable translations this way, we'd have to look at slight modifications to the client so that I can easily extend the UI...

Gábor Hojtsy’s picture

Good! This way of the integration sounds much better :)

akaserer’s picture


you wrote:
"If all this passes scrutiny, I'll port to D6."

i found this feature great for d5.

is the port to d6 still on the todo-list?

podarok’s picture

Title:Add automatic translation suggestions using Google AJAX Language API» Add automatic translation suggestions using Google AJAX Language API (added, need help with bug)
Version:5.x-1.x-dev» 7.x-1.x-dev
Category:feature» support
Priority:Normal» Major
Issue tags:+google translation
4.17 KB
2.56 KB

Tomorrow I got google translate support via jquery.translate-1.3.9.min.js and a few lines of code into module and js

In code (l10n_client.js) there is hardcoded
var trans = $('#l10n-client-string-editor .source-text').text().translate('en','uk');
translation from en to uk
but You can insert Your language tag for testing just change uk to any other

Just put jquery.translate-1.3.9.min.js into l10n_client module folder and apply the patch

In this code there is a problem that I can`t fix now - translation got only one time (need page refresh every time), so I need help, cause I`m not javascript developer 8(((
I think its a little bug with my code, but can`t figure where

jguery plugin from http://code.google.com/p/jquery-translate/

The same trouble with latest dev version of jquery-translate so it is really my bug

Gábor Hojtsy’s picture

How does this work with placeholders like @count (are they left intact?), and links/html markup (are they left intact?).

podarok’s picture

2.54 KB
2.54 KB

Sorry here is a real patch

podarok’s picture

nope Gabor
html code translated nice(tags stay untranslated) but placeholders translated as english text
we need special parser before sending text for translation
But this code if we fix @page refresh@ bug is very nice almost

podarok’s picture

Issue tags:+jquery-translate

possibly this is a bug of jquery-translate

podarok’s picture

Here is a fully working patch with latest jquery-translation (1.4.4) against DRUPAL-7--1

html tags keeps untranslated
placeholders like @count - translated 8((((

podarok’s picture

Status:Needs review» Patch (to be ported)
podarok’s picture

we need to replace only uk with variable of current language
how to find it with javascript?

podarok’s picture

just translated ~100 strings in Ukrainian and have a small statistic
~every 5 needs hand changing, but really fast work aginst po file translation by hands...

Have to be ported to all languages!

podarok’s picture

Status:Patch (to be ported)» Needs review
1.48 KB

after translating > 500 strings make a little patch for existing config
when selecting string in the tree - send it to google without pushing button "Google translate"
-1 click patch

with this patch we can`t change existing translations
but for untranslated strings - very usefull
Need work to check if string already translated - do not send it to Google

andypost’s picture

Status:Needs review» Needs work

I think this addition needs a configuration settings to be Enablable so default behavior is do not use GT for backward compatibility

+++ l10n_client.module	29 Nov 2010 16:25:55 -0000
@@ -89,6 +89,7 @@
+	drupal_add_js(drupal_get_path('module', 'l10n_client') .'/jquery.translate.js');

tabs all over patch

+++ l10n_client.js	29 Nov 2010 21:00:55 -0000
@@ -114,6 +114,8 @@

dreditor shows tabs and ending whitespace

+++ l10n_client.js	29 Nov 2010 21:00:55 -0000
@@ -133,7 +135,14 @@
+  $('#l10n-client-form .translation-target').val($('#l10n-client-string-editor .source-text').text()).translate('en','uk', {alwaysReplace:true, toggle: false, fromOriginal:false});

translation direction should be configurable, as I see it now it's hardcoded

Powered by Dreditor.

podarok’s picture

Status:Needs work» Patch (to be ported)
4.77 KB
24.08 KB

Here is pre-RTBC patch with added option for Fast/Not Fast translation
Also fixed and removed hard-coded language tag and added real language tag from $language->language

So This patch need to be tested and after that possibly commited

podarok’s picture

Status:Patch (to be ported)» Needs review
podarok’s picture

Tested patch on
Drupal7-BETA3 Ukrainian
Drupal7-BETA3 Russian

looks like working for me

need review for other languages

podarok’s picture

reset for testing bot

andypost’s picture

I scare that library http://code.google.com/p/jquery-translate/ is distributed under "Code license: MIT License" so it's not compatible to be included into drupal cvs ... so I included this one as external script (I'm using last stable version)

Settings form is extended to make this feature disabled by default (should be discussed)

Variables are renamed (use_fast changed to l10n_client_auto_gtranslate)

Javascript should not use global variables so replaced with Drupal.settings

Added check to ensure that language is not English so no reason to translate en=>en

PS: I think this feature could be easily added as contrib module but having this in l10n_client is preferable way!

podarok’s picture

Thanks @andypost
checked out this patch at Seven theme and looks like we need a small typo fix with UI
here is a patch for it with Your @andypost updates

still need review

podarok’s picture

Title:Add automatic translation suggestions using Google AJAX Language API (added, need help with bug)» Add automatic translation suggestions using Google AJAX Language API (added, need review patch)
podarok’s picture

Looks like working in
Opera 11
tested on Ukrainian and Russian translations

Powered by Dreditor.

andypost’s picture

Title:Add automatic translation suggestions using Google AJAX Language API (added, need review patch)» Add automatic translation suggestions using Google AJAX Language API
Category:support» feature

Let's get Gabor's review on this.

Gábor Hojtsy’s picture

Status:Needs review» Needs work


- great that you rolled this agains 7.x, perfecto!
- why do you change the submit button? and the textarea height?
- not sure why insist on checking for $language->language != 'en', the l10n_client UI should not show on English, should it?
- why do we have a google translate button even if autotranslation is on? it already happens automatically, right?

Gábor Hojtsy’s picture

BTW would love to include this (once cleaned up) in the next (upcoming) 7.x-1.x and 6.x-2.x release. Thanks for working on it.

podarok’s picture

- why do you change the submit button? and the textarea height?

cause we`ve got a new button "Google translate" that in some themes entering second line of buttons

- why do we have a google translate button even if autotranslation is on? it already happens automatically, right?

Yes, we can hide it, but sometimes jquery-translate got timeouts connecting to google(text just leaves untranslated) and this button can help for sending text by hand

andypost’s picture

We should follow commited #568028: Inform user about submission status
To display ONLY errors of translations (mostly timeouts)

UI is a main trouble - for D7 we should test UI in seven so buttons goes a bit wider so Button moves to second line and breaks UI.

I think it's not a good idea to hide button if auto-translation enbaled because user should have ability to manualy translate in any case.

Probably we should rename button's value from 'Google translate ' to something shorter and maybe change text on other buttons because current UI does not allow to add own buttons without braking UI

$language->language != 'en' is needed because client does not check this condition at all so translating from EN to EN seems confusing

podarok’s picture

still not in 7.x-1.0-beta3 8(