Interns del weblate¶
Nota
Aquest capítol us donarà una visió general bàsica dels elements interns de Weblate.
Weblate deriva la major part de la seva estructura de codi de, i es basa en Django.
Estructura de directoris¶
Visió general ràpida de l’estructura de directoris del dipòsit principal de Weblate:
docsCodi font d’aquesta documentació, que es pot crear amb Sphinx.
dev-dockerCodi Docker per executar el servidor de desenvolupament, vegeu Execució de Weblate localment a Docker.
weblateCodi font de Weblate com a aplicació Django, vegeu Interns del weblate.
weblate/staticFitxers de client (CSS, Javascript i imatges), vegeu Interfície del weblate.
Modules¶
Weblate consta de diverses aplicacions de Django (algunes opcionals, vegeu Mòduls opcionals de Weblate):
accounts
Compte d’usuari, perfils i notificacions.
addons
Add-ons to tweak Weblate behavior, see Complements.
api
API basada en Marco REST de Django.
auth
Autenticació i permisos.
billing
The optional Facturació module.
checks
Translation string Controls de qualitat module.
fonts
Mòdul de comprovacions de representació de fonts.
formats
Capa d’abstracció de format de fitxer basada en el kit d’eines de traducció.
gitexport
El mòdul opcional Exportador de Git.
lang
Mòdul definidor de llenguatge i models plurals.
legal
El mòdul opcional Legal module.
machinery
Integració de serveis de traducció automàtica.
memory
Built-in translation memory, see Memòria de traducció.
screenshots
Gestió de captures de pantalla i mòdul OCR.
trans
Mòdul principal que gestiona traduccions.
utils
Diverses utilitats auxiliars.
vcs
Abstracció del sistema de control de versions.
wladmin
Personalització de la interfície d’administració de Django.
Translation sources¶
A unit has a canonical file source and may have a translation from another
language as its effective source. Keep Unit.source and Unit.source_unit
canonical: repository synchronization and file formats depend on this. Use
effective_source and its language and plural accessors for content shown to
translators. Do not replace source on a copied unit to simulate an effective
source; other fields and related objects still describe the canonical source.
Use Unit.source_snapshot when an operation needs to preserve the source text,
language, plural rules, and terminology metadata together. Its identity defines source changes for
dependency reconciliation, editor conflict detection, and AI diagnostics. For
historical rendering and reports, read the snapshot recorded on the change,
rather than reconstructing it from the current unit.
A missing configured parent remains a custom source: its text is empty, its
language is retained, and its child is blocked. effective_source_unit is
then None. Only removing the workflow or selecting the canonical language
restores the canonical source.
Text-only accessors do not load language or plural metadata. For batch consumers
that need the complete effective source, use
UnitQuerySet.prefetch_translation_parent() alongside their existing unit
prefetches. prefetch_source() already includes this. Ordinary searches keep
the canonical query path and ordinary units retain their existing content hashes.
Source-dependent writes enter source_operation() before locking unit rows.
The outer operation takes a shared project gate and reads its workflow mapping
in one database round trip, including for projects without custom workflows.
Workflow changes take source_project_gate(..., exclusive=True) before
validation or persistence. Configuration changes affecting several projects
acquire their gates in ascending project ID order. Never upgrade a shared gate
to an exclusive one inside an operation.
The database gate function locks first and reads workflows in a separate statement, so a waiter sees configuration committed while it waited. Write paths use this transaction-scoped view rather than cached model settings. Nested operations reuse it; rolled-back savepoints discard their dependency work. Queued dependencies are reconciled before commit and external memory updates are scheduled after commit. Source-change history is written in bulk, preserving individual records while batching their notification dispatch.
Acquire any required repository locks before project gates, then component and unit row locks. Reconciliation itself only changes database state and does not acquire repository locks. Apply this boundary to bulk imports, automatic translation, file-save failures, deletion, and restoration as well as editor writes. Language and plural-rule changes require exclusive gates before their updates. Historical migrations use historical models without these runtime helpers.
Machinery source selection happens before mapping language codes to a provider.
Use get_unit_source_language() for translation and uses_custom_source()
for workflow-specific glossary handling. Provider codes can merge distinct
language variants, so code equality cannot determine whether a workflow source
was selected. Explicit component or secondary source selection takes precedence
over the workflow source.
Background tasks internals¶
Suggeriment
Aquesta secció descriu els elements interns de la tasca d’api. Tasques de fons amb api descriu com configurar Celery per executar les tasques.
Weblate utilitza Celery per executar tasques en segon pla. Algunes tasques es desencadenen per esdeveniments i algunes tasques es desencadenen per programació.
The Celery Beat is used for scheduling tasks, and django-celery-beat is used
to store the periodic task schedule in the database. The tasks schedule is
configured in tasks.py in each of the Django apps.
Les tasques es consumeixen mitjançant diverses cues; l’encaminament es configura a settings.py. Les cues es van dissenyar per separar diferents tipus de càrrega de treball:
celeryLa cua predeterminada on es processen les tasques en segon pla.
notifyOfereix correus electrònics de notificació, tant per a esdeveniments dins de Weblate com per a l’autenticació o el registre. Aquesta és una cua separada per facilitar l’enviament del correu electrònic fins i tot si hi ha un endarreriment d’altres tasques.
memoryActualitza les entrades de la memòria de traducció. La cua d’actualització pot ser llarga quan s’importen cadenes noves, i el processament llarg no importa gaire aquí, de manera que tenir una cua separada evita bloquejar altres tasques.
backupLes tasques de còpia de seguretat no es poden executar en paral·lel i un únic treballador dedicat ho facilita.
translateSe sap que les tasques de traducció automàtica triguen molt perquè afecten a serveis externs.