Chat in real-time or send messages to other users with automatic language translation.

Privatemsg Translator will help users with different default languages to communicate through automatic message translation via the amazing Privatemsg module and Google Translate API integration. When a user sends a message through the Privatemsg module, the Privatemsg Translator module will run through this process:

1. Check if the users have different languages set.

2. If different languages are discovered, send the message to Google Translate.

3. Retrieve the translated message from Google Translate.

4. Display the translated message with the original message.

Currently, the module is ready for alpha release as the module works as described above. For real-time chat tanslation, this module has been tested and works with the Private message with node.js module.

GIT
____________________

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/KennethLancaster/2388665.git privatemsg_translator
cd privatemsg_translator

FUTURE ENHANCEMENTS
____________________

Actively developing future enhancements including the ability to separate the original message and the translated message into better mark-up elements for theming.

INSTALLATION
____________________

To install this module, do the following:

1. Extract the tar ball that you downloaded from Drupal.org.

2. Upload the privatemsg directory and all its contents to your modules directory.

3. Visit admin/modules and enable the "Privatemsg Translator" module.

CONFIGURATION
____________________

To configure this module do the following:

1. Obtain a Google Translate API key (see 3rd PARTY API section below for more information).

2. Go to Configuration -> Privatemsg Translator -> Privatemsg Translator Settings (admin/config/privatemsgtranslator/settings).

3. Check the box for "Enable Google Translate API".

4. In the Google Translate API key box, enter your API key that you should have already retrieved from Google.

5. Save the settings.

DEMO SITE
____________________

* Privatemsg Translator module homepage:
* http://kennethlancaster.com/translator (coming soon)

* Privatemsg Translator module Drupal 7 demonstration website:
* http://translator.kennethlancaster.com/ (coming soon)

DEVELOPERS
____________________

* Developed by Kenneth Lancaster for contribution to the Drupal community:
* http://kennethlancaster.com (coming soon)

* Development contribution/help by Rick Tilley:
* http://pcrats.com/

REQUIRED MODULES
____________________

* Privatemsg Translator module is meant to be used with the Privatemsg module:
* https://www.drupal.org/project/privatemsg

* Required modules may have thier own dependencies.

OPTIONAL MODULES
____________________

* For real-time chat translation you will need to use Private message with node.js:
* https://www.drupal.org/project/privatemsg_nodejs

* Optional modules may have thier own dependencies.

3rd PARTY API
____________________

* Requires a Google Translate api key:
* https://cloud.google.com/translate/

* Google Translate API is not free, be sure to read the details on the Google Translate API's pricing website:
* https://cloud.google.com/translate/v2/pricing

TERMS OF MODULE USE
____________________

By using the Privatemsg Translator module you are agreeing that you will not hold the developers of this module, related modules, or Drupal, liable or resposible for any charges that may incur through use of the Google Translate API. Again, be sure to read the fine print for Google Translate API and be sure to note that you can utilize various settings on the Privatemsg module that can help limit the number of messages sent/received if needed.

DISCLAIMER
____________________

The developers of the Privatemsg Translator module are not affiliated with Google in any way. Nor do the developers receive any compensation from Google for your use of this module. Although, it would be nice if Google did give us a little kick-back;) We hope you enjoy use of this module.

About me:
I am web designer/developer with many years of experience. I have been working with Drupal for many years although, this is my first contributed module. I was working on a Drupal based chat application with Privatemsg and node.js and decided to contribute this module to the community.

Comments

Kenneth Lancaster’s picture

Issue summary: View changes

Added in some information about my background. Thanks.

Kenneth Lancaster’s picture

Issue summary: View changes

Added in better formatting to the description.

PA robot’s picture

Status: Needs review » Needs work

There are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxKennethLancaster23886...

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

Kenneth Lancaster’s picture

Love that robot! Going to work on the issues it presented and make the changes as soon as possible.

Kenneth Lancaster’s picture

Issue summary: View changes

Changed the branch to follow the Drupal standards.

Kenneth Lancaster’s picture

Issue summary: View changes
Status: Needs work » Needs review

Added the new info here in the description that is now included in the readme file. Most recent push addressed the issues presented by PA Robot.

Kenneth Lancaster’s picture

Issue summary: View changes

Formatting issues have mostly been addressed.

mayurjadhav’s picture

Hi Kenneth Lancaster,

Thank you for your efforts, I did some manual review of the code however didn't install it yet. Please find my comments:

Automated Review

Review of the 7.x-1.x branch (commit 65b6913):

There are some errors reported by automated review tools, did you already check them? See
http://pareview.sh/pareview/httpgitdrupalorgsandboxkennethlancaster23886...

Manual Review

Individual user account
[Yes: Follows] the guidelines for individual user accounts.
No duplication
[Yes: Does not cause] module duplication and/or fragmentation.
Master Branch
[No: Does not follow] the guidelines for master branch.
Licensing
[Yes: Follows] the licensing requirements.
3rd party assets/code
[Yes: Follows] the guidelines for 3rd party assets/code.
README.txt/README.md
[Yes: Follows] the guidelines for in-project documentation and/or the README Template.
Code long/complex enough for review
[Yes: Follows] the guidelines for project length and complexity.
Secure code
[Yes: Meets the security requirements.]
Coding style & Drupal API usage
[List of identified issues in no particular order. Use (*) and (+) to indicate an issue importance. Replace the text below by the issues themselves:
  1. (*) Do not add .module in .info And .info file should end with new line.
  2. (*) privatemsg_translator_admin_settings_form doc: is wrong.
  3. (*) Unnecessary function doc is declared on line 95-98
  4. (*) Variable assign should have single space before and after "=", see line(41, 43, 66, 68 and so on)
  5. (*) Unnecessary parenthesis added. see line (130, 131, 142, 143 and so on)
  6. (*) Use check_plain / t() on line 142, 143, 222 and 227.
  7. (*) Do not use db_query() instead use db_select().
  8. (*) Unused variable ($result) is declared on line 184 and 193.
  9. (+) Try to use drupal_add_js/ Move javascript code to .js file. see line 178-180.
  10. (+) Check curl is enabled or disabled using function_exists() in hook_requirements().

The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.

If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.

This review uses the Project Application Review Template.

mayurjadhav’s picture

Status: Needs review » Needs work
Kenneth Lancaster’s picture

Issue summary: View changes

Privatemsg Translator new branch named for dev, also named a branch that would follow the release format. All with most of the requested changes.

Kenneth Lancaster’s picture

Status: Needs work » Needs review

Hi mayurjadhav,

Thanks for taking the time to review my module. I've made lots of changes per your suggestions and per the Pareview.sh code check (which is pretty clean now except for it complaining about the readme file).

In regards to the master branch issue, the directions on that link are bit confusing, they are presented as if the project is out of sandbox. So I was really confused as to what to do. I made the default branch 7.x-1.x and even though I deleted the branches for Master and 7.x-x.x through Sourcetree they still show up in the list on Drupal.org, but do not show up in my list of remote branches. How do I delete the ones on Drupal now? And what should the branch be for this to be acceptable?

I did not know how to fix this, privatemsg_translator_admin_settings_form doc: is wrong. or to be more precise, I don't understand what exactly is wrong. I tried to find the answer to this in forums and the manual. If you can give me a specific link, example or direction I would greatly appreciate it.

If I use check_plain / t() on the lines you were indicating I get an error from Pareview.sh and also I wanted to point out that everything is already being cleaned by the Privatemsg module before my module ever grabs the text from the other module. Then Google only sends back plain text I believe. I can look at this more, but I don't know if this is required here or not. I would appreciate your view on this, should I add it back in and ignore the error?

For this, Do not use db_query() instead use db_select() is this a hard requirement? I've seen many modules that use query and most of the posts I have read say this is a faster method too which is pretty important since this is also meant to run with real-time chats too. I'm looking at improving the db query in other ways too, so can this just be done at a later time when I am adding some more enhancements?

I will definitely implement "Try to use drupal_add_js/ Move javascript code to .js file" and the other recommendation for "Check curl is enabled or disabled using function_exists() in hook_requirements()". Later development releases will include these enhancements.

I would like to at least get this out of sandbox and into development release. Again, I really appreciate your help. Thanks again.

mayurjadhav’s picture

Hi Kenneth Lancaster,

privatemsg_translator_admin_settings_form doc: is wrong.
function name doesn't match with your comment doc.

use check_plain / t() on the lines you were indicating
perfect if it is already cleaned then no need to clean it again.

Do not use db_query() instead use db_select()
Yes i know db_query is faster than db_select, But i think you need to follow drupal coding standards like at some places you used db_select and at some places db_query. You can use db_query if query is more complex and affecting the performance using db_select.

Thanks.

Kenneth Lancaster’s picture

Hi mayurjadhav,

Thanks again. I'm hoping that the "privatemsg_translator_admin_settings_form doc: is wrong" is as simple as I am now thinking, lol. I've uploaded the change in the latest push. Glad to hear the t() should be fine and I will work on the db_select() as soon as I have some free time in the next day or so.

Thanks!

Kenneth Lancaster’s picture

Status: Needs review » Needs work

Moving this back to needs work while I look at the db_select and test on a fresh Drupal install.

Kenneth Lancaster’s picture

Status: Needs work » Needs review

I've just pushed the latest version with all the required/requested changes.

smakisog’s picture

@Kenneth: Hello, i have few notices which can help make your module be more better:

1. Take away module settings links to separate page, just add

$items['admin/config/privatemsgtranslator'] = array(
   ...
   'page callback' => 'system_admin_menu_block_page',
   'file' => 'system.admin.inc',
   'file path' => drupal_get_path('module', 'system'),
  );

2. Use system_settings_form to save forms variables

/**
 * Implements privatemsg_translator_admin_settings_form().
 */
function privatemsg_translator_admin_settings_form($node, &$form_state) {
  ...
  return system_settings_form($form);
}

/**
 * Process a validated privatemsg_translator_admin_settings_form_submit().
 */
function privatemsg_translator_admin_settings_form_submit($form, &$form_state) {
  $form_state['rebuild'] = TRUE;

  // Notify user.
  drupal_set_message(t('Privatemsg Translator settings have been saved.'));
}
gisle’s picture

Assigned: Kenneth Lancaster » Unassigned

This has been sitting unreviewed in the queue for nine months because the project owner assigned the review task to himself.

It is not a good idea to assign the issue to yourself if you want other people to review it. Please see this page about assigning ownership to issues.

Also, making it necessary to obtain a Google Translate api key to be able to test the project may limit the number of potential reviewers. You should provide some alternative (e.g. a free API that simulates Google's) for people who just want to test (and don't care if the "translation" is just changing text into uppercase).

bazaalt.organ’s picture

Status: Needs review » Needs work

Hi Kenneth Lancaster,

privatemsg_translator.module line 127

    if ($privatemsg_translator_recipient_lang_code == $privatemsg_translator_author_lang_code) {
      next($recipient);
    }
    else {

I think instead of the next you should use continue to skip the current item processing in the foreach loop.
Otherwise many of referenced variables will not be available under the code like $response_code, $response_decoded, etc which are initialized within the else condition block.

From the line 143 you have two blocks which do almost same things (if block is duplicated to else block) I think it would be great (for maintainability and performance) to organize them to a common function.

Line 172:

    if ($response_code != 200) {
      // Erorr message received, no translation received.
      echo '<script language="javascript">';

I think you shouldn't use echo to display any error, instead you can use the drupal_set_message or similar functions.
'alert(" Fetching translation failed! Server response code:' should be translatable -> t()

There are some typos in the code:
for instance
line:137 ...suject...
line:145 ...transalation
line:173 ..Erorr...

lots of missing parameter type from doc comments

ashwinsh’s picture

Hello Kenneth Lancaster,

In file privatemsg_translator.module, line no. 186

$result_message = db_insert('privatemsg_translator_msg')->fields(array(
        'privatemsg_translator_mid' => $privatemsg_translator_mid,
        'privatemsg_translator_thread_id' => $privatemsg_translator_thread_id,
        'privatemsg_translator_recipient_id' => $privatemsg_translator_recipient_id,
        'privatemsg_translator_lang_code' => $privatemsg_translator_recipient_lang_code,
        'privatemsg_translator_message' => $privatemsg_translator_message,
      ))->execute();

It should be as

$result_message = db_insert('privatemsg_translator_msg')->fields(array(
        'privatemsg_translator_mid' => $privatemsg_translator_mid,
        'privatemsg_translator_thread_id' => $privatemsg_translator_thread_id,
        'privatemsg_translator_recipient_id' => $privatemsg_translator_recipient_id,
        'privatemsg_translator_lang_code' => $privatemsg_translator_recipient_lang_code,
        'privatemsg_translator_message' => $privatemsg_translator_message,
      ));
	  
$result_message->execute(); 

Or you can change it as follows:

db_insert('privatemsg_translator_msg')->fields(array(
        'privatemsg_translator_mid' => $privatemsg_translator_mid,
        'privatemsg_translator_thread_id' => $privatemsg_translator_thread_id,
        'privatemsg_translator_recipient_id' => $privatemsg_translator_recipient_id,
        'privatemsg_translator_lang_code' => $privatemsg_translator_recipient_lang_code,
        'privatemsg_translator_message' => $privatemsg_translator_message,
    ))->execute();

Same change at line no. 193 for $result_subject.

Thank you,

PA robot’s picture

Status: Needs work » Closed (won't fix)

Closing due to lack of activity. If you are still working on this application, you should fix all known problems and then set the status to "Needs review". (See also the project application workflow).

I'm a robot and this is an automated message from Project Applications Scraper.