Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Integrating vanilla with google translate?

jrocjroc New
edited December 2012 in Vanilla 2.0 - 2.8

Hi

Just wondering if it is possible to use google translate with vanilla. I currently use vanilla embedded in wordpress and have just added google translate to wordpress. This was easy they give you some code to put in the header and another bit of code for the google translate drop down box which can go into any widget area.

I then tried to test it out on vanilla. I added the header code to the head section in default.master.tpl.

<meta name="google-translate-customization" content="6c9e7e03d4779e3c-d0eac95256f1163b-g549cd2d6b9bd9561-e"></meta>

But wasn't sure where to add the drop down box code as I guess you have to create and define a new area on the page for where it is going to be displayed before you paste in the code but not sure how to do that -

<div id="google_translate_element"></div><script type="text/javascript"> function googleTranslateElementInit() { new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, multilanguagePage: true}, 'google_translate_element'); } </script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

So just wondering if this would be possible or if I am overlooking some very obvious reasons why it won't work as it seems like the sort of thing that someone else would have already done by now if it was possible.

Thanks

Comments

  • Options
    jrocjroc New
    edited December 2012

    Managed to get it working :)

    Can only get it working in when using the Annotated_CSS theme but it seem to works great. I created some different posts in Greek, Finnish, and Lithuanian and then selected English as the language and it automatically translated them all. So there is the potential to have a multilingual forum with everyone being able to post using their native language and also view all the other posts from many different languages in whatever language they choose. Obviously google translate is not perfect so you still get a few (often hilarious) mistranslations but definitely has some potential.

  • Options
    whu606whu606 I'm not a SuperHero; I just like wearing tights... MVP

    Glad you got it working.

    If it works in that theme there is no reason why this shouldn't work in any theme, really.

    I made annotated_css as a way to show new users how to make the sort of changes to Vanilla people would typically want.

    Did you put the code in the 'Quick Links' section of default.master?

  • Options

    If it works in that theme there is no reason why this shouldn't work in any theme, really.

    That's what I thought but I couldn't get it to work (but probably because I'm doing something stupid). I didn't put the code in the Quick Links section. In the Annotated_CSS theme I put the drop down box code in default.master.php after the head tag and before the menu. When I do this translate box displays at the top of the forum in the centre. Can see it here - spondyhelp.com/vanilla (the site is still in development and nobody is using the forum).

    <head> <?php $this->RenderAsset('Head'); ?> <div id="google_translate_element"></div><script type="text/javascript"> function googleTranslateElementInit() { new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false, multilanguagePage: true, gaTrack: true, gaId: 'UA-33872034-1'}, 'google_translate_element'); } </script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> <div class="Menu">

    I tried playing around with putting the code in a few different places in a few different themes but only got bonk errors. The other themes had default.master.tpl files instead of .php (not sure if that makes any difference). I'm am ok with CSS and html but am a bit out of my depth with adding stuff in vanilla at the moment but am keen to learn more.

    I made annotated_css as a way to show new users how to make the sort of changes to Vanilla people would typically want.

    Yeah it was a good idea, I found it really useful when I was learning how to play around with the CSS in vanilla and now it has come in useful again.

  • Options
    x00x00 MVP
    edited December 2012

    It is probably becuase most themes are using smarty templates. You need to enclose scripts in {literal} {/literal} tags.

    grep is your friend.

  • Options
    whu606whu606 I'm not a SuperHero; I just like wearing tights... MVP

    As @x00 says, .tpl files are Smarty Templates.

    Using the literal tags as suggested should get things working.

  • Options

    That works perfect, thanks.

Sign In or Register to comment.