1

Im begineer on django. Im try create multilanguage blog.

I use django 2.1.2 and Python 3.7.1

Now, i can easily translate urls, keywords, etc use to "gettext_lazy" and working awesome...

But i can't find any way or plugin for translate my posts models.

I try install django-modeltranslation but i cant use. I think this plugin is incompatible with my django version... Because i take _clone() got an unexpected keyword argument '_rewrite' error all time.

I have no idea how to solve it.

What is solution best way for translate for my posts?

I want see my Articles in admin like this; https://image.ibb.co/kiuFFA/Screenshot-16.jpg

setting.py lang like settings like this;

from django.utils.translation import gettext_lazy as _
LANGUAGE_CODE = 'en'
LANGUAGES = (
    ('de', _('Deutsch')),
    ('en', _('English')),
)

MULTILINGUAL_LANGUAGES = (
    "en",
    "de",
)

my base urls.py like this;

from django.conf.urls.i18n import i18n_patterns
from django.utils.translation import gettext_lazy as _

urlpatterns = [
    path('i18n/', include('django.conf.urls.i18n')),
]
urlpatterns += i18n_patterns(
    path(_('admin/'), admin.site.urls, name="admin"),
    path(_('about/'), views.about, name="about"),
    path(_('contact/'), include("contact_form.recaptcha_urls")),
    path('', include("article.urls")),
    path(_('user/'), include("user.urls")),
    path('', views.index, name="index"),
    prefix_default_language=True,
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

my model.py like this;

class Article(models.Model):

    author = models.ForeignKey("auth.User",on_delete = models.CASCADE, verbose_name="Author")
    title = models.CharField(max_length = 120, verbose_name="Title")
    category = models.ForeignKey('Category', on_delete = models.CASCADE, null=True, blank=True)
    content = RichTextField(verbose_name="Content")
    created_date = models.DateTimeField(auto_now_add=True, verbose_name="Created Date")
    image = models.ImageField(blank=True, null=True, verbose_name="Add image (.jpg .png)")
    slug = models.SlugField(unique=True, max_length = 130)

    def __str__(self):
        return self.title

and my admin.py like this;

@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):


    list_display = ["title", "category", "created_date", "author"]
    list_display_links = ["title", "author", "created_date"] 
    search_fields = ["title","content"] 
    list_filter = ["created_date","author"] 
    prepopulated_fields = {"slug":('title',)}

Thank you very much in advance.

Aytek
  • 224
  • 4
  • 16

1 Answers1

1

You're probably right that currently django-modeltranslation do not support Django 2.1.2 and/or Python 3.7.1. Their docs say they support Python 3.6 and Django 2.0 and latest commit is on Jul 2, 2018.

From here you have a few choices:

  • Fix the bug in django-modeltranslation and contribute to the project.
  • Use another translation Django package that works with Django 2.1.2 and Python 3.7.1 (check here: https://djangopackages.org/grids/g/i18n/).
  • Use django-modeltranslation but downgrade Django to 2.0 and/or Python to 3.6.
Etienne
  • 12,440
  • 5
  • 44
  • 50
  • can't I create a model for this? example; i create in model two area like this; title_en = models.CharField(max_length = 120, verbose_name="Title") title_de = models.CharField(max_length = 120, verbose_name="Title") But then I don't know how to connect them on my language... – Aytek Nov 08 '18 at 20:35
  • Yes you can do that but then you need to add some mechanism to return the right field in function of the current language. This is what some of those packages do. So you need to make the choice between writing the necessary code yourself or using a package already done and tested by many persons. If I can I choose the later. Personnaly I've used django-Transmeta (https://github.com/Yaco-Sistemas/django-transmeta/) for many projects. It's really simple and only do mostly what you describe here. But I don't know if it support latest Django/Python version? – Etienne Nov 08 '18 at 21:01
  • thanks for help but transmeta not working on my django version:/ ... im still searching solution for this... – Aytek Nov 08 '18 at 21:59