deschler / django-modeltranslation

Translates Django models using a registration approach.
BSD 3-Clause "New" or "Revised" License
1.35k stars 259 forks source link

BooleanField fallback bug #358

Open fabiocaccamo opened 8 years ago

fabiocaccamo commented 8 years ago

Steps:

I think that BooleanField(s) should be excluded from the default fallback behavior.

fabiocaccamo commented 8 years ago

I solved it by disabling fallback_languages in the translation options: fallback_languages = {'default':()}

In any case I think that this should be the default behavior for BooleanFields.

zlorf commented 8 years ago

I'll check this. You're right - False value of BooleanField shouldn't cause fallback.

SalahAdDin commented 8 years ago

But, why have you a BooleanField translated? Use django gettext function for it, it's easy.

zlorf commented 8 years ago

I think the idea is to have a checkbox for every language, as in the example: published.

fabiocaccamo commented 8 years ago

@zlorf exactly :)

SalahAdDin commented 8 years ago

I don't understand you yet.

zlorf commented 8 years ago

The goal is not to display translated True/False (which can be made with gettext), but to have a set of boolean fields per language. Consider Article class: it has title, content and published flag (BooleanField). And developer want to have title and content translated, as well as separate checkbox for controlling publication of article for every language. So that he can publish article e.g. in English and German, but don't publish in Spanish yet, since the Spanish translation is missing.

SalahAdDin commented 8 years ago

Ah, now i understand! Thanks.

Paul424 commented 7 years ago

Just experienced the exact same thing; see for my original question: http://stackoverflow.com/questions/41998415/how-to-model-a-many-to-many-relation-when-the-target-model-is-a-tuple-in-django/ it explains why this is a nice feature...

liminspace commented 5 years ago
from modeltranslation.utils import fallbacks

with fallbacks(False):
    is_published = object.published
viktoradavid commented 5 years ago

I just hit the same issue :( Going with fallbacks disabled for now... MODELTRANSLATION_ENABLE_FALLBACKS = False

liminspace commented 5 years ago

MODELTRANSLATION_ENABLE_FALLBACKS is a global option. so it can be not a good idea as only BooleanField has problem with fallback

EnriqueSoria commented 2 years ago

It can be solved by overriding fallback_undefined:

class Product(models.Model):
    published = models.BooleanField(...)
@register(Product)
class ProductTranslationOptions(TranslationOptions):
    fields = ('published', )
    fallback_undefined = {
        "published": None,
    }