violinman Posted May 31, 2017 Share Posted May 31, 2017 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 Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 31, 2017 Share Posted May 31, 2017 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. Quote Link to comment Share on other sites More sharing options...
violinman Posted May 31, 2017 Author Share Posted May 31, 2017 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 Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 31, 2017 Share Posted May 31, 2017 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. Quote Link to comment Share on other sites More sharing options...
violinman Posted June 1, 2017 Author Share Posted June 1, 2017 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 Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 1, 2017 Share Posted June 1, 2017 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. Quote Link to comment Share on other sites More sharing options...
violinman Posted June 1, 2017 Author Share Posted June 1, 2017 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 Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 1, 2017 Share Posted June 1, 2017 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. Quote Link to comment Share on other sites More sharing options...
violinman Posted June 1, 2017 Author Share Posted June 1, 2017 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 Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 1, 2017 Share Posted June 1, 2017 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} Quote Link to comment Share on other sites More sharing options...
violinman Posted June 1, 2017 Author Share Posted June 1, 2017 I will try it in the way you suggest, I have never come across {literal} in php or html before, but then it is a long time since I did any real programming! Brian Quote Link to comment Share on other sites More sharing options...
violinman Posted June 1, 2017 Author Share Posted June 1, 2017 I cannot get it to work in the header, I have tried every combination but it gives a white screen every time, strange that it will work if I put it into a document but not anywhere within the main.php skin file. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 2, 2017 Share Posted June 2, 2017 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}…</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> Quote Link to comment Share on other sites More sharing options...
violinman Posted June 2, 2017 Author Share Posted June 2, 2017 Thank you DB, I will give that a try. Brian Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 2, 2017 Share Posted June 2, 2017 You will need to figure out how to get it to show on small, however. It may be as simple as changing this part to take out the class part: <div class="right text-right show-for-medium-up" id="box-session"> Quote Link to comment Share on other sites More sharing options...
violinman Posted June 4, 2017 Author Share Posted June 4, 2017 Hi DB, well not sure how but it all seems to be working ok, thank you for all your help. Brian Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 4, 2017 Share Posted June 4, 2017 Glad that worked for you! I think I'm going to put this on my stores, too! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.