Index: l10n_community/l10n_community.css =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/l10n_community.css,v retrieving revision 1.1.2.10.2.6 diff -u -p -r1.1.2.10.2.6 l10n_community.css --- l10n_community/l10n_community.css 10 Sep 2009 09:15:03 -0000 1.1.2.10.2.6 +++ l10n_community/l10n_community.css 19 Oct 2009 06:55:29 -0000 @@ -166,6 +166,10 @@ table.l10n-server-translate label.option background: url(images/icon_copy.gif) no-repeat; } + .l10n-community-google-translate { + background: url(images/icon_google-translate.gif) no-repeat; + } + .l10n-translate { background: url(images/icon_toolbox.gif) 0px 0px no-repeat; } @@ -201,6 +205,7 @@ ul.l10n-community-strings li { ul.l10n-community-strings li .buttons { margin-left:-20px; float:left; + clear:both; } .l10n-community-string .original { Index: l10n_community/l10n_community.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/l10n_community.js,v retrieving revision 1.1.2.8.2.5 diff -u -p -r1.1.2.8.2.5 l10n_community.js --- l10n_community/l10n_community.js 15 Oct 2009 08:46:40 -0000 1.1.2.8.2.5 +++ l10n_community/l10n_community.js 19 Oct 2009 06:55:29 -0000 @@ -33,6 +33,13 @@ l10nCommunity.init = function() { $('span.l10n-community-copy').click(function() { l10nCommunity.copyString(this); ;}) + + if (Drupal.settings.l10n_google_translate) { + $('span.l10n-community-google-translate').click(function() { + //l10nCommunity.copyString(this); + l10nCommunity.googleTranslate(this); + ;}) + } // Screw AJAX submit -- we'll just hard submit the form for now $('span.l10n-save').click(function() { @@ -214,6 +221,87 @@ l10nCommunity.copySuggestion = function( return false; } +/* + * Make a suggestion with Google Translate + */ +l10nCommunity.googleTranslate = function(elem) { + var item = $(elem).parents('li').find('div.string > div'); + var parentlist = $(item).parents('ul.l10n-community-strings'); + var original = $('.original', item).text(); + var sid = item.attr('class').substring(7); + var service_errors = false; + + if (sid.indexOf('-') > 0) { + // Copying orignal plural string or active plural translation. We should + // get the original sid prefix and then copy the strings to the textareas. + sid = sid.split('-'); + sid = sid[0]; + + /** + * While google.language.translate() is a asynchronous call and we cannot pass additional arguments + * to the callback, we cannot simply use the "i" counter because "i" may increments faster. + * As a workaround we will explicitly call the translator for the English variants #0 & #2 and + * then simply fill the next ones with the English variant #1. + */ + + // Variant #0. + source = $('.string-'+ sid +'-0 .original', parentlist).text(); + google.language.translate(source, 'en', Drupal.settings.l10n_language, function(result) { + if (!result.error) { + $('#l10n-community-translation-'+ sid +'-0').val(result.translation); + } + else { + service_errors = true; + } + }); + + // Variant #1. + source = $('.string-'+ sid +'-1 .original', parentlist).text(); + google.language.translate(source, 'en', Drupal.settings.l10n_language, function(result) { + if (!result.error) { + // Fill #1 and other possible variants that this language may have. + for (i = 1; i < Drupal.settings.l10n_num_plurals; i++) { + $('#l10n-community-translation-'+ sid +'-'+ i).val(result.translation); + } + } + else { + service_errors = true; + } + }); + + } + else { + // Use Google API to retrieve the translation + google.language.translate(original, 'en', Drupal.settings.l10n_language, function(result) { + if (!result.error) { + $('#l10n-community-translation-'+ sid).val(result.translation); + } + else { + service_errors = true; + } + }); + } + + if (service_errors) { + return; + } + + // Show the editing controls. + $('#l10n-community-wrapper-' + sid).show(); + + // Check the suggestion box + $('#edit-'+ sid +'-translation-is-suggestion').attr('checked', true); + + // Switch to translate pane. The pane is in the translation column, so + // if we are in the source column, we need to switch columns. + var parent = $(elem).parents('td.source, td.translation'); + if (parent.get(0).className == 'source') { + parent = $(parent.get(0)).siblings(); + } + var tool = $('.l10n-translate', parent); + l10nCommunity.switchPanes(tool, 'translate'); +} + // Global killswitch if (Drupal.jsEnabled) { $(document).ready(l10nCommunity.init); Index: l10n_community/l10n_community.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/l10n_community.module,v retrieving revision 1.1.2.23.2.57 diff -u -p -r1.1.2.23.2.57 l10n_community.module --- l10n_community/l10n_community.module 7 Oct 2009 18:21:36 -0000 1.1.2.23.2.57 +++ l10n_community/l10n_community.module 19 Oct 2009 06:55:29 -0000 @@ -1297,11 +1297,14 @@ function l10n_community_theme($existing, 'arguments' => array('type' => NULL, 'class' => NULL, 'extras' => ''), ), 'l10n_community_strings' => array( - 'arguments' => array('items' => NULL, 'form' => TRUE), + 'arguments' => array('items' => NULL, 'form' => TRUE, 'is_source' => TRUE), ), 'l10n_community_copy_button' => array( 'arguments' => array(), ), + 'l10n_community_google_translate_button' => array( + 'arguments' => array(), + ), // pages.inc 'l10n_community_progress_columns' => array( 'arguments' => array('sum' => NULL, 'translated' => NULL, 'has_suggestion' => NULL), @@ -1375,6 +1378,10 @@ function theme_l10n_community_button($ty // Clear form button. $text = t('Clear'); break; + case 'google-translate': + // Create suggestions with Google + $text = t('Google suggestion'); + break; } return ' '. $text .''; } @@ -1383,7 +1390,7 @@ function theme_l10n_community_button($ty * Theme a list of translatable strings. Adds a copy button to each string * for quickly copying its source text into a translation form. */ -function theme_l10n_community_strings($items, $form = TRUE) { +function theme_l10n_community_strings($items, $form = TRUE, $is_source = FALSE) { $output = "