abdnh / anki-incontext

An Anki add-on that shows random example sentences each time you review a vocabulary card
https://ankiweb.net/shared/info/385420176
GNU General Public License v3.0
3 stars 1 forks source link

Possibility of adding other languages? #2

Open ghost opened 2 years ago

ghost commented 2 years ago

Hey! Hope you're doing fine :) Wondering if I could manually add other languages, and if you could possibly explain to me how to do this? I got as far as downloading other languages from tatoeba, but they're not working when using the addon in anki. Maybe I'm doing something wrong? Thanks!

abdnh commented 2 years ago

Hi!

Did you follow the example I posted in the other issue? Can you tell me the steps you followed so far? After creating a file in the providers folder as I explained there, you have to write a function to pull the examples from the file. You can copy the from_tatoeba function in tr.py, changing just the filename to get a file like this:

import os
from typing import List
import csv
import re

from .. import consts

def from_tatoeba(word: str) -> List[str]:
    word = word.lower()
    pattern = re.compile(f"\\b{re.escape(word)}\\b")
    matches = []
    try:
        with open(
            os.path.join(consts.VENDOR_DIR, "jpn_sentences.tsv"),
            encoding="utf-8",
            newline="",
        ) as f:
            reader = csv.reader(f, delimiter="\t")
            for row in reader:
                sentence = row[2]
                if pattern.search(sentence):
                    matches.append(sentence)
    except FileNotFoundError:
        pass
    return matches

NAME = "Japanese"
PROVIDERS = [from_tatoeba]

The jpn_sentences.tsv used here must be inside the providers/vendor folder. The zip files you download from https://tatoeba.org/en/downloads should be extracted to get the .tsv files.

ghost commented 2 years ago

Oh you're right, I'd already received your answer in the other post...Will try and get back to you :D

abdnh commented 2 years ago

An update on this: I've made the Tatoeba fetcher support more languages. You can download the new release from here: https://github.com/abdnh/anki-incontext/releases/tag/0.1

You only have to put the *.tsv file under the user_files/tatoeba folder for the add-on to pick it up now. Currently supported languages are listed here. I plan to make it so that it supports all Tatoeba languages automatically in the near future.

soliviantar commented 12 months ago

This is working for Spanish with downloaded Tatoeba sentences. I tried making Spanish work with Glosbe and Tatoeba without the downloaded sentences, but it didn't work (but I just added "es" to the supported languages in glosbe.py and tatoeba.py .

In facto, Glosbe and Tatoeba (without database) is not working for English either (I'll open a new issue).