Jump to content

[Resolved] Google translate in header.


violinman

Recommended Posts

Hello, could someone please advise me as to which files I need to modify to add the Google translate to the header, either to the left or right of the search box. I found the header in the skin main.php file, do I add the display box there?

It has two parts to it, one is a "meta name" bit which should go in the head if possible, the other block goes where you want the plugin to be displayed, it has two divs and a Google script link.

I have been using it on my old site for many years and as I sell worldwide it is a worthwhile addition.

Many thanks,

Brian

 

Link to comment
Share on other sites

The header in main.php would be for the meta name part. You likely will need to put it in {literal}script{/literal}.

If you want it next to your search box, you will probably need to change the number of columns allotted to the search box and possibly the logo. Foundation uses 12 columns, so if you shave one off of search and one off of logo in the main.php, you have created a space for two columns for your translate box.

Link to comment
Share on other sites

Thank you for your reply, could you expand on the{literal}script{/literal} the actual line of code is:

<meta name="google-translate-customization" content="fbf7401f77452570-feb54b900254ef56-g54139a6ff8d778ad-1a"></meta>

I take your point about the number of columns, I have removed the session/login box which was to the left of the search box, will that then free up those columns?

Thanks,

Brian

 

Link to comment
Share on other sites

Ah! Something about what you said made me think it was a script, which requires the literal braces to work. The literal braces may be needed for the Google script part.

But the meta part doesn't look like a script. Just add it to the rest of the meta lines in main, and see if it works.

The space for the session/login box is now available - try using the same div's the session box had, and see if it looks right.

Link to comment
Share on other sites

Hi DB, it might help if I give you the other bit as well as you might have an idea how I place the code in the header, this bit is placed where you want the Google translate to appear.

<div id="translate">
<div align="left">
<div id="google_translate_element"></div><script type="text/javascript">

function googleTranslateElementInit()
{
new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'de,en,es,fr,it,ja,ko,th,zh-CN,zh-TW', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false}, 'google_translate_element');
}
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</div>
</div>

Thank you,

Brian

Link to comment
Share on other sites

I'm not going to be able to help, other than guessing. If I were doing it on my own site I would make a safe copy of box.session.php and then try editing my version, keeping the div arrangement in that file and put your Translate code in there. Then putting {include file='templates/box.session.php'} back in main.php.

Link to comment
Share on other sites

Ok I will give that a try, I did save a page to templates called google_translate.php and put the code in there and called it in the way you suggest - {include file='templates/google_translate.php'} but still no luck, it just crashed the site! Strange though, If I save a document with both parts of code in it, when I open the document it works fine. I wonder if there needs to be an entry somewhere for the file google_translate.php for cubecart to be aware of it?

Brian

 

Link to comment
Share on other sites

3 minutes ago, violinman said:

I wonder if there needs to be an entry somewhere for the file google_translate.php for cubecart to be aware of it?

I don't see any reason why that would be needed, since it's not going to be saving any translations in your database.

"Crashing" (white page??) sounds like you either didn't form your google_translate.php file properly, or it's that literal issue.

Link to comment
Share on other sites

I am not quite sure what you mean by "literal" issue, could you please explain in simple terms. I saved the box.session.php file as the google_translate.php and then just replaced the reference to the session box with the google code stuff. Maybe it is the literal bit that is causing the problem!

Brian 

Link to comment
Share on other sites

Did you try with and without {literal}your Google script code{/literal} in your google_translate.php?

{literal}
 <div id="translate">
<div align="left">
<div id="google_translate_element"></div><script type="text/javascript">

function googleTranslateElementInit()
{
new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'de,en,es,fr,it,ja,ko,th,zh-CN,zh-TW', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false}, 'google_translate_element');
}
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</div>
</div> 
{/literal}

 

Link to comment
Share on other sites

I tried it on one of my test stores, and it worked, although it needs some cosmetic improvements.

In main.php:

      <meta name="description" content="{if isset($META_DESCRIPTION)}{$META_DESCRIPTION}{/if}">
      <meta name="keywords" content="{if isset($META_KEYWORDS)}{$META_KEYWORDS}{/if}">
      <meta name="robots" content="index, follow">
      <meta name="generator" content="cubecart">
<meta name="google-translate-customization" content="fbf7401f77452570-feb54b900254ef56-g54139a6ff8d778ad-1a"></meta>
     

In box.session.php:

<div class="right text-right show-for-medium-up" id="box-session">
  <!-- {if $IS_USER}
   <a href="#" data-dropdown="session" class="button small">{$CUSTOMER.first_name} {$CUSTOMER.last_name}'s Account Details <svg class="icon"><use xlink:href="#icon-caret-down"></use></svg></a><br>
   <ul id="session" data-dropdown-content class="f-dropdown">
      <li class="text-left"><a href="{$STORE_URL}/index.php?_a=profile" title="{$LANG.account.your_details}">{$LANG.account.your_details}</a></li>
      <li class="text-left"><a href="{$STORE_URL}/index.php?_a=vieworder" title="{$LANG.account.your_orders}">{$LANG.account.your_orders}</a></li>
      <li class="text-left"><a href="{$STORE_URL}/index.php?_a=addressbook" title="{$LANG.account.your_addressbook}">{$LANG.account.your_addressbook}</a></li>
      <li class="text-left"><a href="{$STORE_URL}/index.php?_a=downloads" title="{$LANG.account.your_downloads}">{$LANG.account.your_downloads}</a></li>
      <li class="text-left"><a href="{$STORE_URL}/index.php?_a=newsletter" title="{$LANG.account.your_subscription}">{$LANG.account.your_subscription}</a></li>
      {foreach from=$SESSION_LIST_HOOKS item=list_item}
      <li class="text-left"><a href="{$list_item.href}" title="{$list_item.title}">{$list_item.title}</a></li>
      {/foreach}
      <li class="text-left"><a href="{$STORE_URL}/index.php?_a=account" title="{$LANG.account.your_account}">{$LANG.common.more}&hellip;</a></li>
      <li class="text-left"><a href="{$STORE_URL}/index.php?_a=logout" title="{$LANG.account.logout}">{$LANG.account.logout}</a></li>
   </ul>
   {else}
   <a href="{$STORE_URL}/login.html" class="button white small nopad-sides">{$LANG.account.login}</a> / <a href="{$STORE_URL}/register.html" class="button white small nopad-sides">{$LANG.account.register}</a>
   {/if} -->

{literal}
 <div id="translate">
<div align="left">
<div id="google_translate_element"></div><script type="text/javascript">

function googleTranslateElementInit()
{
new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'de,en,es,fr,it,ja,ko,th,zh-CN,zh-TW', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false}, 'google_translate_element');
}
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</div>
</div> 
{/literal}
</div>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...