0

I am building django admin application with multi language translation feature. I have tested with django-transmeta, django-linguo and a couple of libraries. The problem with the above libraries is, for instance i am using 20 languages and I have a model called Product and it contains 10 fields. Now the situation is, 20 languages * 10 fields = 200 fields will be shown in add Product, edit Product. It looks nasty. Is there any other alternative to make translation very crispy and simple ?

One more thing, I wanna to translate the whole content in the admin panel depends on the language choose. For example, the following screenshot gives more information https://docs.google.com/file/d/0B6j95vYIfu8eem1OdkNVbXNudm8/edit

Thanks for Advance !!

vamsi
  • 75
  • 1
  • 9
  • If you want to translate your models to different languages you can't avoid translating everything. I recommend you to check [Django-Rosetta](https://github.com/mbi/django-rosetta) is a very useful tool that helps on translation. – AlvaroAV Apr 07 '15 at 09:09
  • @Liarez: Did u use before ? Because, I am still unclear, whether it fulfills my criteria which I had mentioned in the question. – vamsi Apr 07 '15 at 09:27
  • You don't need that package to do translation, that package provides you a useful administration page to create your translations, but yes, you have to translate it by yourself – AlvaroAV Apr 07 '15 at 09:44

2 Answers2

0

About the mess on your app "add Product" admin page caused by the extra fields for translation, I think you can solve it with django-modeltranslation and bootstrap-modeltranslation.

The package bootstrap-modeltranslation is made for django-admin-bootstrapped, and it requires it. But, take a look at its code. His approach to the problem is by using javascript on django admin to organize the additional translation fields onto tabs. Maybe you can adapt this solution to your needs.

For translating templates, it's better to use the gettext approach and tools like django-rosetta, django-translation-manager. You can have more info for the internationalization features of Django on django docs.

Odyr Sohn
  • 1
  • 2
0

Step 1 : gettext

Move as much as you can to gettext. Having the duplicate data from your different products in your PO file will make your app faster, DRY and easyer to translate.

Step 2 : Django Admin Edit/Add

Customise your Django Admin to your needs.

I suggest you create a fieldset for every language.

class FlatPageAdmin(admin.ModelAdmin):
    fieldsets = (
        ('Advanced options', {
            'classes': ('collapse',),
            'fields': ('product_name', 'product_description'),
        }),
    )

It will make your add Product and edit Product a lot cleaner. Alternatively, you can also use a tab for each language instead of the ModelAdmin fieldset.

See https://pypi.python.org/pypi/django-tabbed-admin/0.0.3

Step 3 : Make broad changes to the fields widgets

django-transmeta allows you to change the widget of all related language field at once. See documentation.

from transmeta import canonical_fieldname

class BookAdmin(admin.ModelAdmin):
    def formfield_for_dbfield(self, db_field, **kwargs):
        field = super(BookAdmin, self).formfield_for_dbfield(db_field, **kwargs)
        db_fieldname = canonical_fieldname(db_field)
        if db_fieldname == 'description':
            # this applies to all description_* fields
            field.widget = MyCustomWidget()
        elif field.name == 'body_es':
            # this applies only to body_es field
            field.widget = MyCustomWidget()
        return field