Django live editing
Live editing on Django lets you open your own pages in Dialecto’s editor and edit a text in place while
runserver runs. It is a middleware in the dialecto-django package, active only when DEBUG is on.
Install
Install it as a development dependency, in your dev requirements only.
pip install dialecto-django
The package has no runtime dependencies.
Setup
Add the middleware under if DEBUG:, first in the list, or just inside GZipMiddleware. Then run runserver.
# settings.py
if DEBUG:
MIDDLEWARE.insert(0, "dialecto_django.middleware.InContextMiddleware")
With DEBUG = False, or with DIALECTO_IN_CONTEXT=off as an environment variable or a Django setting, Django
drops the middleware at load. Nothing is patched, no /__dialecto route answers and no marker reaches a page.
INSTALLED_APPS += ["dialecto_django"] is optional. It starts the same add-on in AppConfig.ready().
Editable text
Only text from .po files inside your repository is marked: LOCALE_PATHS and your apps’ locale/ folders.
Django’s own and packages’ text, djangojs, and a missing pgettext translation are not marked.
Pages are marked only while Dialecto’s editor is open, for a top-level GET of a page on a loopback address.
POSTs, JSON, XHR and frames are never marked.
A draft previews in place for:
- plain text;
%(name)splaceholders, where%%is a literal%;ngettextplurals, in any locale.
The overlay reads the values off the page and the plural form from the marker. Brace placeholders ({name}),
positional %s placeholders, and a page value that cannot be read back unambiguously show Reload to
preview, which renders the draft on the server.
Settings
Each setting can be a Django setting, an environment variable, or an option in a DIALECTO = {...} dict in
settings.py, which uses lower-case names.
| Variable | Meaning |
|---|---|
DIALECTO_URL |
The Dialecto to use. Default https://app.dialecto.eu. |
DIALECTO_PROJECT |
The project’s number. |
DIALECTO_PATHS |
URL prefixes the add-on is limited to. |
DIALECTO_ROOT |
The repository folder. Default the git top level. |
With django-csp, the add-on adds the Dialecto origin to the CONTENT_SECURITY_POLICY directives when it starts.
State, meaning drafts and the marking flag, is per process, so run one worker. Avoid {% cache %} and
cache_page while you edit, and use DummyCache.
dialecto-django doctor, run with DJANGO_SETTINGS_MODULE set, checks the middleware position, django-csp,
i18n_patterns, the cache backend, --forwarded-allow-ips='*' and the worker count.
Pull requests
Your edits are saved in Dialecto as drafts on your project, and the pull request is opened from the sidebar.
Dialecto reads committed .po files only. .mo files are build output, so they are never read, sent or
written. Run compilemessages in your own build after a merged Dialecto pull request.
See the Django guide for the scan and the usage check in CI.