HugoFara / lwt

Learn languages by reading! A language learning app stemmed from Learning with Texts (LWT).
https://hugofara.github.io/lwt/
The Unlicense
169 stars 19 forks source link

Fix right-frame google translation link. #59

Closed jzohrab closed 1 year ago

jzohrab commented 2 years ago

When using a Google Translate URL, every "translate click" fails on the first click, which is annoying. This is a very simple fix.

The current pre-PR code uses a series of calls to eventually open a new window with a header Location change. I believe that Google has blocked this for XSS attack reasons. This change just makes the proper URL using plain javascript and then opens the window. It's very clear what's happening with this new code, but I don't know enough project history to say if this is an acceptable change or not.

Note that the 'translate sentence' in the reading pane pop-up is still broken, because it uses a slightly different set of calls, and still relies on the Location header change.

Issuing this PR to master because master is currently broken, so it's a hotfix.

jzohrab commented 1 year ago

Fixes #58 -- but apparently I should edit a different file, as this file is the minified file. Need some guidance from @HugoFara as it's not clear to me which file to edit, or how to run the minifying process (that should be documented for future devs as well).

jzohrab commented 1 year ago

PR updated, js code moved to correct spot and minify run. Whoops! Should have read docs/contribute :-/

HugoFara commented 1 year ago

Hello! I've merged your pull request after some adjustments!

Finally the solution I've opted for was to rewrite the createTheDictLink JS function. It was simply calling PHP function createDictLink before, now it does the same thing as before but in pure JS. I had to do so to consider the case when there is no '###' in the dict URL, so you have to append content to the end of the string.

I removed the case where two '###' where present in the URL, because it was indicating a non-UTF-8 encoding. Back in 2011 (LWT 1.0.2), it may have been a good idea but it does no seem of any use today, and made the code unreadable.