django-modeltranslation icon indicating copy to clipboard operation
django-modeltranslation copied to clipboard

language-specific translation for default field

Open ghost opened this issue 11 years ago • 8 comments

I'm writing an app which has translation for en and fa. I've added content to translation fields, when I want to add a post to my app it shows me same translated "My default value" for both en and fa based on current active language. But I want it to be based on field language.

content = models.TextField(_("Session description"), default=_("My default value"))

What I should do to fix this issue?

ghost avatar Jul 19 '14 14:07 ghost

I'm afraid modeltranslation doesn't support this currently. It makes sense however and i think we should try to add it as the default behaviour.

deschler avatar Jul 20 '14 21:07 deschler

Committed a first try in 52e24d6. It might need some additional work, since default can also be a callable. And it requires a unittest.

deschler avatar Jul 20 '14 23:07 deschler

Thanks for your attention and support :+1:

ghost avatar Jul 21 '14 04:07 ghost

@zlorf: What do you think about this feature? Do you see any conflicts it might raise with our fallbacks?

deschler avatar Jul 21 '14 14:07 deschler

@deschler: I'm currently on a vacation, I'll take a look a bit later. ;)

zlorf avatar Jul 24 '14 08:07 zlorf

@deschler It seems ok. I've tried fallback values and it works. But I fear that it may fail with fallback languages. Values in database would be different for each language field (text_en and text_de, for example), and when checking fallback in descriptor one of these fields will yield value different from current default (computed once for against current active language). The solution would be to compute default (or rather undefined) separately for each checked fallback language (https://github.com/deschler/django-modeltranslation/blob/override-default/modeltranslation/fields.py#L337), not once (https://github.com/deschler/django-modeltranslation/blob/override-default/modeltranslation/fields.py#L331)

zlorf avatar Jul 29 '14 19:07 zlorf

Sorry I was busy for a while so I couldn't test this, now I'm back. I guess this feature isn't in 0.8b2 release, also tried to install package using pip install git+git://github.com/deschler/django-modeltranslation.git and it's still same thing, is it possible to release a new version which includes this feature?

ghost avatar Oct 03 '14 04:10 ghost

Hello @deschler, Having translated defaults values is a logical feature to have (thanks @k1-hedayati ), I'm happy you guys worked on it. Shall We initiate a PR for the override-default branch ?

ppython avatar Nov 07 '17 15:11 ppython