Using Django-modeltranslation in combination with PostgreSQL SearchVector

Solution 1:

IIUC, you can just use get_language():

from django.utils.translation import get_language
from django.contrib.postgres.search import SearchVector, SearchQuery, SearchRank

class BookView(APIView):

    def get(self, request):
        q = request.get('q')
        vector = SearchVector(f'name_{get_language()}')
        query = SearchQuery(q)
        matches = Book.objects.annotate(rank=SearchRank(vector, query))\
                      .filter(rank__gt=0.1)\
                      .order_by('-rank')