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

Add modeltranslation support

Open fabiocaccamo opened this issue 8 years ago • 6 comments

Steps to reproduce the problem:

  • more languages, for example: en, it, fr
  • default language: en
  • modeltranslation installed
  • model with a name field and a slug field populated from name
  • name and slug fields are marked for translation in translation.py
  • in the admin populate the name field for all languages using the different values and save it

Current result: All slug values are always (for all languages) the slugified version of name in the default language:

slug_en populated from name_en slug_it populated from name_en slug_fr populated from name_en

Expected result: Each slug value should be the slugified version of name for the corresponding language:

slug_en populated from name_en slug_it populated from name_it slug_fr populated from name_fr

Dirty solution overriding model save method:

#requires always_update = False
def save(self, *args, **kwargs):
    
    for lang_code, lang_verbose in settings.LANGUAGES:
        lang_code = lang_code.replace('-', '_')
        
        setattr(self, 'slug_%s' % lang_code, slugify( getattr(self, 'name_%s' % lang_code, u'') ))
        
    super( NameSlugModel, self ).save( *args, **kwargs )

fabiocaccamo avatar Apr 05 '17 14:04 fabiocaccamo

Check PR #26

fabiocaccamo avatar Apr 06 '17 10:04 fabiocaccamo

Any update about this issue?

fabiocaccamo avatar Feb 28 '19 15:02 fabiocaccamo

+1 It would be really great to have such feature out of the box!!!

parruc avatar Oct 17 '21 14:10 parruc

@justinmayer @parruc still interested in a PR for this issue?

fabiocaccamo avatar Jul 04 '22 10:07 fabiocaccamo

I have done it the ugly way in the save method so I do not strictly need it but I still think it would be beneficial for the project: urls are often based on slugs and having translated slugs that comes from specific language titles would helps with website positioning and user friendliness of the site IMO.

parruc avatar Jul 04 '22 10:07 parruc

@parruc I have the impression that this project is a little bit abandoned by the maintainer.

fabiocaccamo avatar Jul 06 '22 07:07 fabiocaccamo