Main | Why Language Translation is Important »

June 12, 2008

Translate Plugin for MT

Download the plugin by clicking here.

Translate Plugin for Movable Type 4.x

Translate

This plugin allows you to place links on your blogs that will translate the content into multiple foreign languages using the Google Language AJAX APIs.

A. Installation Instructions

       
  1. Copy the contents of the folder to your MovableType directory. Make sure     that the directory structure remains intact.    
  2.    
  3.         Log in to the MovableType dashboard, or refresh the dashboard if you are already logged in.         You should be prompted to "Upgrade".    
  4.    
  5.         Open the Header template (Design - Templates - Template Modules) and insert the <MTTranslateHeader/> tag between the <head> and </head> tags.         This will allow the Google Language AJAX APIs to work on your site on all pages (the tag includes the needed javascript).    
  6.    
  7. Open the Stylesheet template and include the following line after the other "@import" statements:         @import url(<MT:StaticWebPath>/plugins/Translate/css/translate.css);    
  8.    
  9. Modifiy the templates and include the tags in the desired locations (see section B: Using The Tags).
  10.    
  11. Publish your blog. You should see the "Translate" link below each entry.

B. Using the Tags

You must use the <MTTranslateHeader> tag somewhere (ideally in the Header template).

The only other tag is the <MTTranslateMenu> tag which inserts the proper code needed to display the translate menu, which allows the reader to translate the content of the entry. The tag has 2 parameters:

       
  • sourceid (required) - The HTML div id of the content that is to be translated.
  •    
  • sourcelanguage (optional) - The 2 character language code of the original language of the content.     If not specified, "en" will be used by default (English).

For example, you could place the following code into your Summary template:

    <mt:setvarblock name="sourceid">asset-body-<$MTEntryID$></mt:setvarblock>
    <MTTranslateMenu sourceid="$sourceid" />

Make sure that your template has the corresponding id on the appropriate div tag. You may need to add the id yourself if it is not already in your template!
Also note that you will probably need to place the tag in your Entry template as well. Remember, div tag id's must be unique, so use the MTEntryID tag to get the unique id of the entry.

C. Other Stuff

The CSS file can be changed to create the desired style. By default it uses flag icons from http://www.famfamfam.com/lab/icons/flags/ which are named according to country codes (not to be confused with language codes).

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e54fa7efe7883300e5534e4cd78833

Listed below are links to weblogs that reference Translate Plugin for MT:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

I installed your plugin tonight and have set it up according to the instructions. The javascript is referencing the right post id but its not translating the text. Is there something I'm missing here?

Hi Bryan,
Thank you for your effort to make this plugin available. I have an idea for the future releases. It will make a big difference on SEO if the plugin could catch a copy of a translation and save it in the cache. Then we can use different URLs for different languages. Something like a translation script you find here: http://forums.digitalpoint.com/showthread.php?t=42057. This way, search engines could crawl the translations. The only problem with that script is that it requires "Safe mode" to be off and this is not something everyone can decide on.

Hi Bryan!

I've installed your plugin and I see the Translate link appear. When I click it the multiple languages appear. Great!

However, when I click any of the languages (let's say Arabic) it's trying to execute "language_translate('asset-body-10','language-translate-target-10','en','ar','10')". But nothing happens.

I suspect my problem is with the last part of your instructions about the DIV tag. Can you explain in more detail what and where I need to add the "corresponding id on the appropriate div tag"?

Can't wait to see this in action!

For those of you having problems... Yes, you will need to give the DIV tag an ID in order for the translation to work. Basically, you can do this:

div class="asset-body" id="asset-body-$MTEntryID$"
$MTEntryBody$
/div

The default templates do not already give an ID to the DIV tag, so you will need to provide one. Remember, and HTML ID must be unique to the page, and that's why you need to put the MTEntryID in it. Basically, you're telling the MTTranslateMenu tag which DIV tag to translate by passing in its unique ID.

You will probably need to do the same for both the Entry Detail and Entry Summary templates (assuming you are using the default "Classic" templates).

I hope that helps. Please post if are having any more problems.

Thanks, Bryan!

Finally got it working. Your comments aren't allowing me to use HTML but I did have to modify the id="asset-body-$MTEntryID$" above to include angle brackets around $MTEntryID$.

I found the best place for the original two lines of code you provided
was after [open angle bracket]/MTIfNonEmpty[close angle bracket] in both Entry Summary and Entry Detail.

A couple of observations:

If I translate English to English (testing the result to make sure it translates properly) I see some additional line breaks in odd places. Those may be due to Google.

Also, I'd suggest not translating anything in code tags such as when I'm providing technical command line instruction.

Otherwise, I think this is a fantastic plugin! Probably my favorite so far.

Here is another example that worked for me in the Entry Detail template module...

" class="post-alt blog">




">


">

asset-body-


Hi brain,

Could you translate this tutorail in french ? please ^^.


lol :p

hehehe, no without a joke.. I tried to install the plugin but i think i didn't understand anything.
Where the translate file must be uploaded ? In the MT root ? Or in MT/plugins ?

Further problems for me.

Thanks for your answer and for this nice and helpfull plugin.

Just like all plugins for MT, you need to make sure that the directory structure that comes in the zip file remains intact. In other words, make sure that the contents of the "plugins" directory gets put into the "MT/plugins" directory of your MT installation. Also, the contents of the "mt-static" directory need to be copied to "MT/mt-static". I hope that helps.

-Bryan

hi
i installed this plugin but i have many problem.
it shows only empty box on my site
can you get me a complete example?
please see this plugin in my site. i waiting for your response

best regards
Arnoo

Arnoo, it looks like you did not specify the html id for the body of your entry. I'm not seeing an empty box, I see the list of flags and languages. But the links are not translating because you did not set the html id. If you see an empty box, perhaps you need to upgrade your browser. What browser are you using?

Make sure you do this:
div class="asset-body" id="asset-body-$MTEntryID$"
$MTEntryBody$
/div

And then do this:
mt:setvarblock name="sourceid"asset-body-$MTEntryID$/mt:setvarblock
MTTranslateMenu sourceid="$sourceid" /

Post your template code if you are still having problems. I hope that helps,
Bryan

hi Bryan
thanks but i still see the empty box, you can see in this pic: http://i36.tinypic.com/2qlfxuv.jpg
would you show me what you see?
i check my site on 2 computer, my browser is firefox 3 and IE6

this is my template code:
div class="asset-body" id="asset-body-$MTEntryID$"
p $MTEntryBody$ /p
/div
mt:setvarblock name="sourceid" asset-body- $MTEntryID$ /mt:setvarblock
MTTranslateMenu sourceid="$sourceid" /

thanks
Arnoo

Hi bryan
Is it possible to use this plugin with "Typepad"? If yes, the how?
Thanks in advance
sd

Arnoo,
Everything now looks good on your blog to me.
Here is what I see:
http://bryantighe.typepad.com/photos/files/translatearnoo.html

I see the list of languages with flags, and the translation works, too. I think something might be wrong with the javascript on your browser. Do you have javascript disabled? It needs to be enabled if so.


sd,
Sorry, but you can't use this plugin for TypePad, only Movable Type.

I have the translator working but it will not translate the extended part of the entry. Here's my code without open/closing brackets:

mt:setvarblock name="sourceid" asset-body-mt:EntryID
mt:setvarblock
mt:TranslateMenu sourceid="$sourceid"
p
div class="asset-body" id="asset-body-mt:EntryID "
mt:EntryBody
mt:EntryMore
div
.
.
.

orajen - can you post a link so that I can check it out? Your template code looks good to me.

Hi Bryan,

This plug in is great. I notice, though, that if any other divs live within the asset-body-mtentrynumber div, I get lots of garbage...

But if there are no other divs within the translated div, it works great.

Is there a way to exclude a block of html from the translator like

?

pter - Google's translation service should filter out the html. What type of garbage are you getting? There is not a way to exclude certain parts of the content.

Hrm, it's not the divs... Is there an email address I can send the link to? I'd rather not publish the link publicly...

ptr - send it to me at btighe (at) sixapart.com

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment