Django / Configuration
Step 21 of 23
Configure altified.py
Register the model fields Altified should sync and then keep reading those fields normally in your Django code.
Create a starter configuration file from the project root, beside manage.py.
Terminal
python manage.py init_altifiedEdit altified.py and register the models and text fields that should be translated.
altified.py
from shop.models import Product
from blog.models import Post
TRANSLATIONS = {
Product: {
"fields": ["name", "description"],
},
Post: {
"fields": ["title", "body"],
},
}After a field is listed in altified.py, use it the normal Django way. Altified automatically returns the translated value when the active language is not the source language.
Python
def product_detail(request, pk):
product = Product.objects.get(pk=pk)
# These are translated automatically when the active language is not English.
name = product.name
description = product.description- Only register fields that contain user-facing content.
- Altified generates stable keys like db:shop.Product:42:name.
- When a registered model is saved, the SDK syncs those fields to your Altified backend.
- When a registered field is read, the SDK checks cache first and falls back to the original text if needed.