Sorry, was afk for a moment. To enable this for all lessons, not just your own, use a different url. This also simplifies the code get_indexes function. I don’t think we can get away with just one API version unfortunately. Maybe give this a try:
Summary
INDEX_URL = f'https://www.lingq.com/api/v3/{LANGUAGE}/lessons/{LESSON_ID}/sentences/'
def get_indexes():
response = requests.get(INDEX_URL, headers=HEADERS)
if response.status_code == 200:
data = response.json()
indexes = []
for item in data:
index = item.get('index')
indexes.append(index)
return indexes
else:
print(f'Error: {response.status_code}\nResponse: {response.text}')
return []
What happens in this code is if the lesson is not yours to edit it breaks at the getindex stage. So it’s not a bad check for own lesson. I’ll implement a change that displays the sentences in a manipulable GUI if it’s not your lesson.
It must be because I’m the librarian. Maybe it’s not a bad restriction for the add-on. I’m sure there is a way to get access to the individual sentences. But without documentation it’s just trial and error. It’s probably not important enough to spend time on it.
I think I found a suitable URL that might be accessible to all users(potentially?). But I’m a little afraid setting everything to “google translate” might bulldoze human made translations. I won’t spend more time on this, your version is already good enough as is.
Summary
INDEX_URL = f'https://www.lingq.com/api/v3/{LANGUAGE}/lessons/{LESSON_ID}/simple/'
def get_indexes():
response = requests.get(INDEX_URL, headers=HEADERS)
if response.status_code == 200:
data = response.json().get('tokenizedText', [])
indexes = []
for item in data:
if isinstance(item, list):
for subitem in item:
tokens = subitem.get('tokens', [])
for token in tokens:
index = token.get('index')
if index is not None:
indexes.append(index)
return indexes
else:
print(f'Error: {response.status_code}\nResponse: {response.text}')
return []
The /simple URL should be accessible yes. That’s the URL I use in basically every extension to collect initial data. It’s light enough and not cluttered with too much unnecessary stuff.
The addon isn’t approved yet on Firefox. They are usually pretty quick. Maybe check again in a few hours. The source code is available to download if you want to manually install. Instructions are on the bottom of the 1st post on the main page.
LATEST PATCH V1.14 - ROOSTER LESSON TRANSLATOR COMMUNITY VERSION
LIMITATIONS - READ ME
PATCH 1.14 IS ONLY COMPATIBLE WITH FIREFOX BROWSER I HAVE SUBMITTED A DIFFERENT VERSION OF THIS PATCH TO CHROME WHICH IS NOW 100 SENTENCES FOR ALL USERS UNTIL I FIGURE OUT THE PROBLEM
→ BIG PATCH FOR LINGQ SUBSCRIBERS AND LINGQ LIBRARIANS
→ LingQ Lifetime Premium and Monthly premium subscribers can now use this add-on without any translation limit.
→ LingQ Librarians get a 50% reduction in translation time as well as unlimited translations.
I decided to try out the Lesson Translator on a Korean video that only had TL text, and the translation seems pretty darn good.
So far as I can tell (as a beginner and with the help of DeepL—free version, lol). There was one awkwardly worded sentence, but the translation is strong.
This is impressive!
P.S. I’ll have to work with it more, but I wanted to share my initial thoughts. (Just Wow! ) Where are the free translations sourced from?
Translations are requested directly from the LingQ server. Its basically just going to every sentence in sentence mode, pressing translate, gathering results and apply to your lesson.
In a future premium version I will likely allow translations from other sources.
Interesting, I didn’t know LingQ had sentence translation ability, but I have been seeing a lot of mentions of it lately on the Forum… I thought it only worked if you highlight up to 9 words in reader mode.
Is it possible to add a premium feature that allows you to create/display multiple of the same type of translations for a given translation?
For Example:
Human Translation [English Translation 1]: [Translation from the video, or if you’re basically a translator yourself—not me—or just want to put in your own tweaked translation] Direct Translation [English Translation 2]: [Translation that keeps the original structure of the sentence, so you can understand how the sentence is laid out but still see the actual words in your native language—not sure if any programs do this, but one way for users to do this is to write out their LingQ definitions in a pseudo-direct-translation style]
Here is an imperfect example of something that a user can use to (aid them in) creat(ing) a direct translation if tools like this aren’t as accessible/don’t exist:
I have this listed under Rooster Reader premium.
It would be possible to bring this to my extensions but its not possible within the LingQ interface to add a second translation to a lesson. One way I could possibly do this would be to hijack the “Notes” for each sentence and then write some code that modifies the display of the LingQ reader to append the notes under the translation. Or just display them as an additional box in Rooster Reader.
To get your translation we do something like this.
Code
# Function to translate a text
def translate_text(text, input_language, target_language, translation_type, model='gpt-3.5-turbo-16k', temperature=0.5, max_tokens=8000):
# Forming the translation prompt
if translation_type == 'Literal':
prompt = f'Translate the following {input_language} text to {target_language} literally: "{text}"'
else: # 'derived'
prompt = f'Translate the following {input_language} text to {target_language} idiomatically: "{text}"'
This is a good suggestion and ill keep it in mind.
I’ll put this on the notes to export the “Notes” if I go that route.
edit: what the f, I just thought… add the second translation to some obscure language and we can call it like that. like set the literal translation as a Zulu translation or something.
Alright what I’m going to do with this is… Allow you to set a custom translation in lesson editor. with that 2nd translation it will be displayed as an additional box in rooster reader free. i’ll get cracking.
Either of these might work, as I tend to use the notes section (due to the limitations of LingQ) to do something similar to what I described above.
Ah, Makes perfect sense to have it there now that I think about your feedback in this reply!
hmm… This is an interesting thought, but if other users are learning Zulu (or _____ more obscure language), would that through things off for other users?
This would just be a Zulu translation of your lesson. But instead of showing Zulu we show the literal translation. I’m going to experiment see if we can post to a not real language, then I could set custom slots for multiple translations.