django-db-translate is an app with utilites to assist in project-wide translation.
With django-db-translate, you can:
- Select fields from the database to include in .po files using makemessages
- Edit translations directly in the admin site
- Note
- This app is a work in progress and may break unexpectedly.
Add "django_db_translate" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ..., "django_db_translate", ]Add your project's locale directory to your LOCALE_PATHS setting like this:
LOCALE_PATHS = [ BASE_DIR / 'locale' ]Run
python manage.py migrateto create the models.Add a translatable_fields class attribute to any model with fields you want to be translatable:
class MyModel(models.Model): translatable_fields = ('txt_field',) txt_field = models.CharField()Run
python manage.py makemessages --all --include-db-stringsto generate the .po files
Follow steps 1-3 from Quick start (Database Translations)
Include the custom admin site inplace of the standard admin site in your project's URLconf:
from django_db_translate import admin urlpatterns = [ ..., # Your other URLs here path("admin/", admin.site.urls), ]Add "django_db_translate.middleware.DBTranslateAdminMiddleware" to your MIDDLEWARE setting after any other Locale manipulating middlewares:
MIDDLEWARE = [ ..., 'django_db_translate.middleware.DBTranslateAdminMiddleware' ]Give the
Dbtranslate | db translate permissions | Manage translationspermission to any user that requires translation editing permissions