The Internationalization System provides multi-language support for Deep-Live-Cam's user interface. It enables the application to display text in different languages by loading translation files at runtime and providing a translation mechanism throughout the codebase. The system currently supports 10 locales including English (default), Chinese, Russian, Spanish, German, and others.
This document covers the translation mechanism, file format, and integration patterns.
The internationalization system follows a simple key-value translation model:
locales/ directory modules/gettext.py15-17LanguageManager class handles loading and lookup modules/gettext.py4_() provides transparent access to the loaded dictionary modules/gettext.py24-26Key Design Principles:
en) modules/gettext.py12-13_() for all translations modules/gettext.py24Sources: modules/gettext.py4-26 locales/zh.json1-46 locales/ru.json1-45 locales/es.json1-46 locales/de.json1-47
The LanguageManager class in modules/gettext.py encapsulates all translation logic.
| Method | Purpose | Parameters | Return Type |
|---|---|---|---|
__init__ | Initialize manager with default language modules/gettext.py5-8 | default_language: str | None |
load_language | Load translation file from disk modules/gettext.py10-22 | language_code: str | bool |
_ | Look up translated string modules/gettext.py24-26 | key: str, default: str | str |
| Attribute | Type | Purpose |
|---|---|---|
current_language | str | Currently loaded language code modules/gettext.py6 |
translations | dict | Key-value mapping of translations modules/gettext.py7 |
Initialization modules/gettext.py5-8:
The constructor sets the current_language, initializes an empty translations dictionary, and calls load_language.
Language Loading modules/gettext.py10-22:
"en") returns True immediately without loading a file modules/gettext.py12-13locales/{language_code}.json modules/gettext.py15utf-8 encoding and parses the JSON content into self.translations modules/gettext.py16-17False and prints an error if the file is not found modules/gettext.py20-22Translation Lookup modules/gettext.py24-26:
The _ method uses self.translations.get(key). If the key is missing, it returns the default value (if provided) or the key itself.
Sources: modules/gettext.py4-26
Translation files are stored in the locales/ directory with the naming pattern {language_code}.json.
Translation files are flat JSON objects mapping English source strings to translated strings:
| English Key (Key) | Chinese (zh.json) | Russian (ru.json) | Spanish (es.json) | German (de.json) |
|---|---|---|---|---|
"Source x Target Mapper" | "Source x Target Mapper" | "Сопоставитель Источник x Цель" | "Mapeador de fuente x destino" | "Quelle x Ziel Zuordnung" |
"select a source image" | "选择一个源图像" | "выберите исходное изображение" | "Seleccionar imagen fuente" | "Wähle ein Quellbild" |
"Preview" | "预览" | "Предпросмотр" | "Vista previa" | "Vorschau" |
"Start" | "开始" | "Старт" | "Iniciar" | "Starten" |
"Mouth Mask" | "口罩" | "Маска рта" | "Máscara de boca" | "Mundmaske" |
Sources: locales/zh.json2-22 locales/ru.json2-21 locales/es.json2-19 locales/de.json2-19
The following diagram bridges the code entity LanguageManager to the natural language space by showing how a raw string becomes a localized UI element.
Sources: modules/gettext.py16-26 locales/ru.json25
The UI module typically initializes the translation system during its startup sequence.
Sources: modules/gettext.py5-26 locales/zh.json25
default parameter in the _() call modules/gettext.py26key string modules/gettext.py26This ensures the UI always displays meaningful text even when translations are missing or the locale file is corrupted.
The system currently manages translations for approximately 45 unique keys across the application.
| Category | Examples (English Keys) |
|---|---|
| Action Buttons | "Start", "Live", "Destroy", "Add", "Clear", "Submit" |
| Status Updates | "Processing...", "Processing succeed!", "Getting unique faces" |
| Error Messages | "Failed to start camera", "Please select a source image first" |
| Feature Toggles | "Face Enhancer", "Mouth Mask", "Keep audio", "Many faces" |
| File Operations | "save image output file", "select a target image or video" |
Sources: locales/zh.json1-46 locales/ru.json1-45 locales/es.json1-46 locales/de.json1-47
| File | Role |
|---|---|
modules/gettext.py | Core translation engine implementation modules/gettext.py4 |
locales/zh.json | Chinese (Simplified) locale data locales/zh.json1 |
locales/ru.json | Russian locale data locales/ru.json1 |
locales/es.json | Spanish locale data locales/es.json1 |
locales/de.json | German locale data locales/de.json1 |
Sources: modules/gettext.py locales/zh.json locales/ru.json locales/es.json locales/de.json
Refresh this wiki