Bug 396609

Summary: Google translation bar bookmarklet does not work
Product: [Applications] Falkon Reporter: Theo <alpha0x89>
Component: generalAssignee: David Rosca <nowrep>
Status: REOPENED ---    
Severity: normal CC: jurajoravec
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 3.1.0
Sentry Crash Report:

Description Theo 2018-07-17 17:22:07 UTC
The bookmarklet for the Google translation bar found on https://googlesystem.blogspot.com/2009/11/google-translation-bar.html works in Firefox, but not in Falkon. It doesn't work for me in Chrome/Chromium either, but there you have this functionality built-in. Can the bookmarklet be made to work in Falkon? Note that you have to replace "http" by "https" to make it work in Firefox:

javascript:{d=document;b=d.body;o=d.createElement('scri'+'pt');o.setAttribute('src','https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit');o.setAttribute('type','text/javascript');b.appendChild(o);v=b.insertBefore(d.createElement('div'),b.firstChild);v.id='google_translate_element';v.style.display='none';p=d.createElement('scri'+'pt');p.text='function%20googleTranslateElementInit(){new%20google.translate.TranslateElement({pageLanguage:%22%22},%22google_translate_element%22);}';p.setAttribute('type','text/javascript');b.appendChild(p);}void%200
Comment 1 The_assassin 2018-08-11 08:06:30 UTC
I can't get this working on Firefox. But Bookmarklets are working at all in Falkon.
Here is an example you can try on the current page:

================== EXAMPLE BOOKMARKLET ======================

javascript:mt=document.getElementsByTagName('meta')[0].getAttribute('content');if(mt){alert('Content of the current page is: '+mt)};

=============================================================
Comment 2 David Rosca 2018-12-24 14:26:57 UTC
Git commit 956b99c1cb2a3db0f3f429c9eb8f2a38e06862c5 by David Rosca.
Committed on 24/12/2018 at 14:03.
Pushed by drosca into branch 'master'.

BrowserWindow: Use LoadRequest in loadAddress
FIXED-IN: 3.1.0

M  +1    -1    src/lib/app/browserwindow.cpp

https://commits.kde.org/falkon/956b99c1cb2a3db0f3f429c9eb8f2a38e06862c5
Comment 3 Theo 2019-06-06 19:02:48 UTC
The translation bookmarklet still doesn't work for me in Falkon 3.1.0. The_assassin's example works fine.
Comment 4 Juraj 2019-06-07 12:14:53 UTC
Hello,
There is probably some mistake in that code (it is old).

1. As mentioned, you need to use https otherwise it will work only on http sites
2. we can get rid or 'scri'+'pt' and replace it with 'script' (it is easier to read)
3. And here comes the obstacle
 - Remove: v.style.display='none';
   It will display some selectbox to manually trigger translating
 - Use the select box to trigger the translating, the translate bar will appear
 - After this was done, when you use this bookmarklet again on the same tab it will display the selectbox and also the translate toolbar and loads a lots of scripts
4. So I presume it is some kind of error with javascript or some execution thing...
5. The workaround is not so bad...

====

javascript:%7Bd=document;b=d.body;o=d.createElement('script');o.setAttribute('src','https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit');o.setAttribute('type','text/javascript');b.appendChild(o);v=b.insertBefore(d.createElement('div'),b.firstChild);v.id='google_translate_element';p=d.createElement('script');p.setAttribute('type','text/javascript');p.text='function%20googleTranslateElementInit()%7Bnew%20google.translate.TranslateElement(%7BpageLanguage:%22%22%7D,%22google_translate_element%22);%7D';b.appendChild(p);%7D
====
Comment 5 Theo 2019-06-08 13:01:22 UTC
(In reply to Juraj from comment #4)
>  - Remove: v.style.display='none';
>    It will display some selectbox to manually trigger translating
>  - Use the select box to trigger the translating, the translate bar will
> appear

I confirm that this workaround works as described, and here is an interesting observation: once this workaround has been applied and a page has been translated, the original bookmarklet works now on any page on the same site, but only as long as I don't click "Show original" in the translation bar.