Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing Google Translator drop down

I have a website and in this website am adding google translator so that people can see website in different languages

The code that i have added is

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

Now i want to customize the drop down like background color , text color, text size and width how can i do this

Please Help Me

I tried of giving the drop-down opacity 0 and placing my drop down on the same place so that it acts same but its not working....

like image 328
user1561923 Avatar asked Aug 09 '12 10:08

user1561923


People also ask

Can you customize the Google Translate widget?

To customize google translate button/select, use the id #google_translate_element . Then the select tag to customize select option.

How do I manipulate Google Translate?

To tweak a translation:Hover over a translated sentence to display the original text. Click on 'Contribute a better translation' And finally, click on a phrase to choose an automatic alternative translation —or just double-click to edit the translation directly.


2 Answers

I know this is an old post, but I'm sharing my solution here for others who, like me, had/will have the same problem.

The drop down is inside an iframe, so specifying its CSS on your page alone will not help. Here's how I styled my Google Translator drop down menu with jQuery:

$('document').ready(function () {
    $('#google_translate_element').on("click", function () {

        // Change font family and color
        $("iframe").contents().find(".goog-te-menu2-item div, .goog-te-menu2-item:link div, .goog-te-menu2-item:visited div, .goog-te-menu2-item:active div, .goog-te-menu2 *")
            .css({
                'color': '#544F4B',
                'font-family': 'tahoma'
            });

        // Change hover effects
        $("iframe").contents().find(".goog-te-menu2-item div").hover(function () {
            $(this).css('background-color', '#F38256').find('span.text').css('color', 'white');
        }, function () {
            $(this).css('background-color', 'white').find('span.text').css('color', '#544F4B');
        });

        // Change Google's default blue border
        $("iframe").contents().find('.goog-te-menu2').css('border', '1px solid #F38256');

        // Change the iframe's box shadow
        $(".goog-te-menu-frame").css({
            '-moz-box-shadow': '0 3px 8px 2px #666666',
            '-webkit-box-shadow': '0 3px 8px 2px #666',
            'box-shadow': '0 3px 8px 2px #666'
        });
    });
});
like image 150
Ben Y Avatar answered Sep 17 '22 17:09

Ben Y


FOR DROPDOWN language LINK COLOR :

simply add this script into head ..

<script>
var $jt = jQuery.noConflict();
$jt('document').ready(function () {

    $jt('#google_translate_element').on("click", function () {

var $frame = $jt('.goog-te-menu-frame:first');
$frame.contents().find(".goog-te-menu2-item div")
            .css({
                'color': '#544F4B',
                'font-family': 'tahoma',

  }).hover(function(){
   $jt(this).css("background","#eeeeee");
  },function(){
   $jt(this).css("background","");
  }); 
   });
});
</script>
like image 36
Tufail Shaikh Avatar answered Sep 20 '22 17:09

Tufail Shaikh