django-multilingual-ng icon indicating copy to clipboard operation
django-multilingual-ng copied to clipboard

Get None if no translation

Open Natim opened this issue 15 years ago • 5 comments

Hello,

I am looking for this :

menus = Section.objects.select_related().exclude(titleTop__exact='').filter(level__exact=0).filter(menuTop=True).order_by('orderTop')

And I am expecting that titleTop__exact='' exclude the Section without translation in the current language_code of the user.

It was working before but now ? How should I do this ?

Natim avatar Jun 07 '10 13:06 Natim

filters will always try to fall back.

You have two options, either do the queryset in a way that you query the translation model directly or use the global language lock.

ojii avatar Jun 07 '10 15:06 ojii

How can I use the global language lock ?

Natim avatar Jun 07 '10 15:06 Natim

in multilingual/util.py you have:

class GlobalLanguageLock(object):

this class have lock and release, what is more its already initilaised so your code may look as follows:

from multilingual.utils import GLL

GLL.lock('fi')

// some code

GLL.release()

Drachenfels avatar Jun 27 '10 21:06 Drachenfels

Btw.

I'm wondering, if it would be very hard or if there is a simple way to achieve following:

menus = Section.objects.select_related().exclude(titleTop__exact='', related_translation='pl').order_by('orderTop')

Special keyword related_translation that will search for object in polish variant, without looking at global language.

Drachenfels avatar Jun 27 '10 21:06 Drachenfels

So far I did something like this :

    from multilingual.languages import get_translated_field_alias

    if language_code is None:
        language_code = get_language()

    parents = self.get_ancestors()
    items = []

    field_alias = get_translated_field_alias('slug', language_code)

    for a in parents:
        a.slug = getattr(a, field_alias, '')

But with the GlobalLanguageLock it will be easier to make request. Thanks

Natim avatar Jun 28 '10 06:06 Natim