Skip to main content

Self‑Healing Localization

Automatic, self‑maintaining localization for any Python project

Type: Library Author: Tuomas Lähteenmäki
License: MIT
Version: 0.2.1 Status: Development

Python License PyPI TestPyPI Status: Beta Downloads


Primary Links


Overview

Self-Healing Localization Layer (SHL) is a Python localization engine that automatically creates, synchronizes, and maintains language files throughout the lifetime of your application.

What makes SHL different?

Feature SHL Traditional i18n
Missing keys created automatically ✅ ❌
Missing language files created automatically ✅ ❌
Zero runtime dependencies ✅ ❌ (often require gettext, Babel, etc.)
BCP-47 region subtag support ✅ 🟡 (limited)
GLFM language validation (7,900+ languages) ✅ ❌
Self-healing fallback chains ✅ ❌
Smart translation routing ✅ ❌

Key Benefits

  • No more manual JSON editing.
  • No more "missing translation" errors.
  • No more incomplete language packs.
  • Write code in your native language. SHL handles the rest.

Features

Base language

The base language is fully controlled by the developer. It is the language in which you primarily write the application’s texts. SHL uses it as:

  • the fallback when a translation is missing in the target language
  • the source when creating or synchronizing other language files

Self‑Healing UI Localization

  • Missing language files are created automatically.
  • Missing keys are added on the fly.
  • Developer-defined base language is used as fallback.
  • Region subtags preserved: zh-TW, pt-BR get their own files.

Self‑Healing AI Prompt Template Localization

Large Language Model (LLM) applications often require localized prompt templates in addition to localized UI text. SHL manages both through the same self-healing localization engine.

  • Missing template files are generated automatically.
  • Base templates are copied as fallback.
  • Missing template keys are added automatically.
  • Same region subtag support as UI localization.

Unified High‑Level Engine

The LocalizationEngine ties everything together:

  • Ensures languages exist.
  • Synchronizes all languages with the base language.
  • Provides a single interface for UI text and prompt templates.
  • Optional GLFM language validation with BCP-47 tags.

GLFM Integration (7,900+ languages)

  • GLFM Lite (default): ~428 KB, 20 nearest languages for fallback.
  • Full GLFM (optional): ~925 MB, all 7,900+ languages for research and AI.
  • Language validation with BCP-47 tags.
  • Language family fallback chains.

Smart Translation Routing (v0.2.0)

  • Automatically selects the best available service (MyMemory → LibreTranslate).
  • Automatic fallback on rate limits or downtime.
  • Language support detection with 24-hour cache.
  • Machine translation is opt-in (m_translation_enabled=False by default).

Zero Dependencies

Zero runtime dependencies. Pure Python library. Optional online translation services. Works everywhere.


Quick Start

Installation

Stable (PyPI)

pip install self-healing-localization

Latest Development (TestPyPI)

pip install -i https://test.pypi.org/simple/ self-healing-localization==0.2.1

Environment Variables (.env)

Create a .env file in your project root (optional):

MYMEMORY_EMAIL=your@email.com
LIBRETRANSLATE_API_KEY=your-api-key
LIBRETRANSLATE_URL=https://libretranslate.com

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

# Initialize the engine (user language = Finnish, base = English)
engine = LocalizationEngine(lang_code="fi", base_lang="en")

# 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)

2. Configuration via config.conf

Create a config.conf in your project root:

[SETTINGS]
language = fi
base_lang = en
m_translation_enabled = true
engine = LocalizationEngine()  # reads language and settings from config.conf
print(engine.ui_text("welcome", "Welcome!"))

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}
engine = LocalizationEngine(lang_code="fi", 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="en", config={"m_translation_enabled": True})

# Switch to Finnish
engine.set_language("fi")
print(engine.ui_text("greeting", "Hello!"))  # "Hei!" (Machine-translated)

# Switch to Swedish
engine.set_language("sv")
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="fi")
print(result)  # "Hei maailma"

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

Release files for self-healing-localization 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for self-healing-localization 0.2.1
File Size Uploaded
self_healing_localization-0.2.1.tar.gz 488.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for self-healing-localization 0.2.1
File Interpreter ABI Platform
self_healing_localization-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 969.8 kB

Release files / self_healing_localization-0.2.1.tar.gz

Download URL self_healing_localization-0.2.1.tar.gz
Size 488.4 kB
Tags Source
SHA-256 checksum
How to use checksums
88225e3e3bf38d9229f3cc1ec5829f7970c750fe4791dd5e2ae8958b39d21684
BLAKE2b-256 checksum
How to use checksums
ece480032ea28b9605dca6561637b40b38989ae05a55caba0e2cd8cf0405206a
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.2.1-py3-none-any.whl

Download URL self_healing_localization-0.2.1-py3-none-any.whl
Size 481.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7d6a2be387e217d170a9d5474e6e7e0d190abdc728d98f3b7d7eba3062d790f
BLAKE2b-256 checksum
How to use checksums
84c9417d029cd34f9533db8b889a868e626319f8821061b1b2b377b02d6bfa03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.2.3

2 release files

0.2.2

2 release files

This release

0.2.1 This release

2 release files

0.1.7

2 release files

0.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page