A bit late but for anyone who find this I would recommand one of 2 options:
templates/{lang}/{page name}.html
and a localized_template
function in viewsPage
modellocalized_template
functionwrite untranslated page templates in language-specific subfolders (ex en/my-page.html
, en-gb/my-page.html
, es/my-page.html
)
write a localized_template
utility function, for ex in an app named my_app
# my_app/views.py
from os import path
from django.http import HttpResponse
from django.shortcuts import render
from django.utils.translation import get_language
def localized_template(name: str) -> str:
return path.join(get_language(), name)
# usable in render like
def my_page(request: HttpRequest) -> HttpResponse:
return render(request, localized_template("my-page.html"))
Page
modelmy_app
# my_app/models.py
from django.db.models import Model, TextField
class Page(Model):
content: TextField[str, str] = TextField()
add django model translation or an equivalent and configure it for your app
setup the model translation
# my_app/translation.py
from modeltranslation.translator import register, TranslationOptions
from .models import Page
@register(Page)
class PageTranslationOptions(TranslationOptions):
fields = ('content',)
After that, how you edit the model is up to you. If you need to persist default data, you could dump it as fixtures:
./manage.py dumpdata my_app.page > default_pages.json