URL manipulation including a field replacement
I set up a link to Google Translate in my template like this:
<span id='Google'><a href="https://translate.google.com/#view=home&op=translate&sl=en&text={{English}}&tl=it" style="color: rgb(64, 64, 144)">Google</a></span>
This works fine. The contents of field "English" are passed to Google Translate and translated to Italian.
I want a script which uses if ("{{info-Did:}}" == ...) (using the add-on "Additional Card Fields Fork for 21") to check which deck I am in and change the "it" to "nl" so that English is translated to Dutch. But URL manipulation seems to be complicated by the field replacement. I tried a script which just replaces the whole span with a complete URL containing the "nl". Logically it should work except apparently the field name {{English}} is not properly replaced with the field contents. In fact the error says unrecognized identifier.
Can anyone solve this for me?
Comments are closed, but you can start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Bruce Plumb on 06 May, 2020 07:30 AM
Solved it myself!
Actually two possible explanations. First I put the {{English}} in a span:
<span id='English'>{{English}}</span>
then assigned the span contents to a variable:
var EnglishText = document.getElementById('English').innerHTML;
Then concatenating with the variable +EnglishText+ instead of +{{English}}+ works fine even after replacing the Google span.
But actually the problem might have been just from using {{edit:English}} (from the add-on "Edit Field During Review Cloze"). That add-on unfortunately adds a line break which might have been the only problem messing up the URL