Does electron webview support language translation


#1

Hi,

I am creating browser in electron for my project.
Since electron uses chromium will it able to support language translations like translate function in chrome/chromium.

Thanks
Jk


#2

I’m also very curious about this - did you ever figure this out?


#3

I send you message please check


#4

I’m also very curious about this. can you add extensions for webview same chrom?
thanks


#5

Hi,

I injected google translate API into my website using preload script
Please check google website translate API terms and conditions to make sure you are not breaking any of their terms

preload.js

//inject google translate scripts
document.addEventListener("DOMContentLoaded", function(event) {
    document.onreadystatechange = function () {
        if (document.readyState ==  "complete" ) {
            (function() {

                if (document.getElementsByTagName('html')[0].lang != "en") {

                    var insideScript1 = document.createElement('script');
                    insideScript1.text = 'function googleTranslateElementInit() { new google.translate.TranslateElement({pageLanguage: \'en\', includedLanguages: \'en\', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, multilanguagePage: true}, \'google_translate_element\');}';

                    var insideScript2 = document.createElement('script');
                    insideScript2.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';

                    var tCode = document.createElement('div');
                    tCode.id = 'translateCode';
                    tCode.innerHTML = '<div id="google_translate_element"></div>';
                    tCode.style.cssText = 'z-index: 999999999999;  float: left;position: absolute;left: 0px;top: 58px;background-color: white;';
                    document.body.appendChild(tCode);

                    tCode.appendChild(insideScript1);
                    tCode.appendChild(insideScript2);

                    var first = document.body.children[0];
                    document.body.insertBefore(tCode, first);

                    var interval = setInterval(styleWorks, 600);

                    function styleWorks() {
                        var googBannerFrame = document.getElementsByClassName('goog-te-banner-frame');
                        var googGadgetSimple = document.getElementsByClassName('goog-te-gadget-simple');
                        if (googBannerFrame.length === 1) {
                            googBannerFrame.style.cssText = "position: 'relative'; top: '-37'; height: '37'";
                            googGadgetSimple.style.cssText = "fontSize: 20; display: 'inline-block'; fontSize: 20; padding-top: 4px;padding-bottom: 9px;";
                            clearInterval(interval);
                        }
                    }
                }

            })(document);
        }
    }
});

Thanks
Jk