Self‑Healing Localization (SHL) Library
Automatic, self‑maintaining localization for any Python project
- Author: Tuomas Lähteenmäki
- License: MIT
- Version: 0.3.0
- Type: Library
- Status: stable, test, dev
Primary Links
-
Canonical Repository (Codeberg): https://codeberg.org/lahtis/Self_Healing_Localization
-
GitHub Mirror: https://github.com/lahtis/Self-Healing-Localization
-
Documentation: https://codeberg.org/lahtis/Self_Healing_Localization/src/branch/main/docs
-
Demonstration: https://youtu.be/t5veRZtt3dU?si=ADD4yS5C2VwNKx9f
-
SHL Policy Editor: https://codeberg.org/lahtis/shl_policy_editor
Overview
Self‑Healing Localization Library (SHL) is a dependency‑free Python library that automates application localization and independently repairs missing translations. The library creates, updates, and synchronizes translation files throughout the application’s lifecycle without manual maintenance.
SHL follows a self‑healing principle: when the application requests a missing translation key, the library automatically generates it, fetches a machine translation if needed, and stores the result in the correct language file. This makes localization deterministic and reduces developer workload.
Features
- Automatic creation of missing translations
- Automatic generation of new language files
- BCP‑47 language code support (e.g., fi‑FI, pt‑BR, zh‑TW)
- GLFM‑based language validation
- Machine translation support: Microsoft Translator, DeepL, Google Translate, MyMemory, LibreTranslate, LibreTranslate Community, Papago Translate, Yandex Translate and Localhost.
- Self‑healing localization pipeline
- Unified high‑level localization engine
- Offline and online support
- Zero‑dependency core
- Free and open‑source - SHL is fully free; paid providers may require separate subscriptions.
Translation Providers Status
The following translation providers have been tested and are currently operational:
- MyMemory (translated.net)
- DeepL
- LibreTranslate
- LibreTranslate Community
The other supported providers are implemented but have not yet been fully tested.
Developer note: SHL is a zero-budget project. Provider support is implemented first, while full provider testing is performed as resources allow. MyMemory, DeepL, LibreTranslate, and LibreTranslate Community have currently been tested successfully. Some providers may require a temporary paid subscription or other access in order to complete testing.
Memory Providers Status
The following memory providers have been tested and are currently operational (as of v0.2.17):
- MyMemory.dev
Note that
MYMEMORY_API_KEY(translated.com) andMYMEMORY_DEV_API_KEY(mymemory.dev) are separate variables for separate services.
Limitations
SHL does not process user‑audited or user‑modified files. The library does not perform self‑healing corrections on user data files or configuration files; it operates strictly within the application’s own localization layer.
Architecture
SHL’s architecture is based on a layered model where the localization engine routes translation requests through a router to different providers. The provider layer uses configuration that defines provider priorities, timeouts, environment variables, and content filtering.
Quick Start
Installation
Creating a virtual environment
python3 -m venv venv
source venv/bin/activate
Stable (PyPI)
pip install self-healing-localization
Latest Development (TestPyPI)
pip install -i https://test.pypi.org/simple/ self-healing-localization==0.3.0
Environment Variables (.env)
Create a .env file in your project root (optional):
MYMEMORY_EMAIL=your@email.com
LIBRETRANSLATE_API_KEY=your-api-key
LIBRETRANSLATE_COMMUNITY_API_KEY=your-api-key
MYMEMORY_DEV_API_KEY=your-api-key
DEEPL_API_KEY=your-api-key
GOOGLE_API_KEY=your-api-key
MICROSOFT_TRANSLATOR_KEY=your-api-key
NAVER_CLIENT_ID=your-api-key
NAVER_CLIENT_SECRET=your-api-key
YANDEX_API_KEY=your-api-key
LOCAL_TRANSLATOR_API_KEY=your-api-key
DETECTLANGUAGE_API_KEY=your-api-key
Environment variables are optional, but required for providers that use API keys. If a provider has no API key, SHL will still work offline and fall back to local translation or self‑healing behavior.
Configuration via config.conf
Create a config.conf in your project root:
[SETTINGS]
language = fin
base_lang = eng
m_translation_enabled = true
The library generates
shl-config.jsonandshl-policy-config.jsonautomatically in the project root.
Quick Start
1. Basic UI Localization
Initialize the engine and start retrieving text. Missing keys are added to your JSON files automatically.
from shl.engine import LocalizationEngine
shl.setup_logging("DEBUG")
# Initialize the engine ISO 639-3 (user language = Finnish, base = English)
engine = LocalizationEngine(base_lang="eng")
# If 'welcome_msg' is missing, it is created with the given default value
title = engine.ui_text("welcome_msg", "Welcome to the App!")
print(title) # "Tervetuloa sovellukseen!" (if translation exists)
SHL interprets this as:
- base_lang="eng" → source code strings are English
- lang_code="fin" → user wants Finnish UI
So SHL does:
-
- Look for welcome_msg in fin.json
-
- If missing:
- Create the key in fin.json
- Use the default value "Welcome to the App!" as the English source
- Translate English → Finnish
-
- Return the Finnish result
Note: SHL uses ISO 639-3 (ISO 3-letter) language codes, such as eng for English, fin for Finnish, ita for Italian, and fra for French.
Core takeaway
- base_lang = the language your source JSON files are written in
- lang_code = the language the user wants to see in the UI right now Everything else in SHL’s behavior flows from that.
How SHL interprets these two parameters
1) base_lang
This is the language of your canonical UI strings — the language your codebase “speaks”.
SHL uses base_lang to:
- know which JSON file is the authoritative source
- know what language missing keys should be stored in
- know what language to translate from when generating other languages
2) lang_code
This is the language the user wants to see.
Examples:
- Finnish user → lang_code="fin"
- English user → lang_code="eng"
- Italian user → lang_code="ita"
SHL uses lang_code to:
- decide which JSON file to read from
- decide which JSON file to write new keys into
- decide which language to translate to
3. Enable Machine Translation
Machine translation is disabled by default. Enable it when you want missing texts to be translated automatically.
config = {"m_translation_enabled": True} # you can overwrite config in code
engine = LocalizationEngine(lang_code="fin", config=config)
text = engine.ui_text("new_key", "Hello World!")
# → "Hei maailma!" (automatically translated to Finnish)
4. Prompt Templates
SHL handles localized AI prompt templates the same way as UI text.
prompt = engine.template("summarize_task", "Please summarize the following text:")
If the template file for the current language does not exist, it is created automatically using the base language as the source.
5. Dynamic Language Switching
Switch languages at runtime without restarting the application.
engine = LocalizationEngine(lang_code="eng", config={"m_translation_enabled": True})
# Switch to Finnish
engine.set_language("fin")
print(engine.ui_text("greeting", "Hello!")) # "Hei!" (Machine-translated)
# Switch to Swedish
engine.set_language("swe")
print(engine.ui_text("greeting", "Hello!")) # "Hej!" (Machine-translated)
6. Region Subtag Support
# Brazilian Portuguese and European Portuguese in separate files
engine = LocalizationEngine(lang_code="pt-BR") # → pt-br.json
engine = LocalizationEngine(lang_code="pt-PT") # → pt-pt.json
# Traditional and Simplified Chinese in separate files
engine = LocalizationEngine(lang_code="zh-TW") # → zh-tw.json
engine = LocalizationEngine(lang_code="zh-CN") # → zh-cn.json
7. Direct Translation (Smart Routing)
from shl.engine.translation import translate_text
# Automatically chooses the best provider
result = translate_text("Hello World", target_lang="fin")
print(result) # "Hei maailma"
8. UI translations
Check the latest documentation files.
Contributing
Contributions are welcome.
This project aims to become a new standard for open‑source localization — simple, automatic, and self‑maintaining.
License
MIT License — free for personal and commercial use.
Vision
Localization should never be a burden.
With SHL, any project can become multilingual — automatically, reliably, and without manual maintenance.
No more missing translations. No more incomplete language packs. Localization that heals itself.
#localization • #i18n • #l10n • #self-healing • #translation • #multilingual #json • #python • #developer-tools • #automation • #templates • #cli #ai-assisted • #language-files • #internationalization • #localization-engine
Metadata
Release files for self-healing-localization 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| self_healing_localization-0.3.0.tar.gz | 587.0 kB | Without provenance | Details for self_healing_localization-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| self_healing_localization-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for self_healing_localization-0.3.0-py3-none-any.whl |
Total release size: 1.2 MB
Release files / self_healing_localization-0.3.0.tar.gz
| Download URL | self_healing_localization-0.3.0.tar.gz |
|---|---|
| Size | 587.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
acc722c13cb5441d658b9ef6ccf486f24750e987216e4ed3b09c205a5114f6b5
|
|
BLAKE2b-256 checksum How to use checksums |
dfd50ee4ced8efca24b853c86022eaca0290a4f8d3b32c93ab7b3df80df3cbdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / self_healing_localization-0.3.0-py3-none-any.whl
| Download URL | self_healing_localization-0.3.0-py3-none-any.whl |
|---|---|
| Size | 593.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e4692f293158220bb257883a4f223b5741057a9bd6e58ab6687e2eedd795728
|
|
BLAKE2b-256 checksum How to use checksums |
ca1d68e3bbcb32b245752d527a672740be3041ac0f1895f4071304c0fe28f866
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for self-healing-localization 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.