A simple, thread-safe Python module for easy localization (multilingual support)
Project description
Simple Localize
A simple and efficient Python module to easily add localization (multilingual support) to your projects.
Installation
pip install simple-localize
Quick Start
import simple_localize
simple_localize.init_localizer('your_translations.json')
print(simple_localize.get_text('your_text_key')) # Auto-detects your language
Features
- 🌍 Auto-detects your system language
- 📁 JSON-based translations (easy to edit)
- 🔄 Switch languages on the fly (per-thread safe)
- 🎯 Text formatting with variables
- ⚠️ Missing key warnings with helpful suggestions
- ⚡ Zero dependencies - uses only Python standard library
- 🔒 Thread-safe - safe to use in multi-threaded apps (Flask, FastAPI…)
Basic Examples
# Get text in your system language
message = simple_localize.get_text('welcome_message')
# Get text in specific language
french_msg = simple_localize.get_text('welcome_message', 'fr')
# Change current language
simple_localize.set_language('es')
# Use variables in text
greeting = simple_localize.get_text('greeting', name="Alice")
API Reference
| Function | Description | Example |
|---|---|---|
init_localizer(file, lang) |
Initialize with JSON file | init_localizer('my_translations.json') |
get_text(key, lang, **kwargs) |
Get translated text | get_text('hello', name="John") |
set_language(lang) |
Change language for the current thread | set_language('fr') |
get_current_language() |
Get current thread's language code | Returns 'en' |
get_available_languages() |
List all available languages | Returns ['en', 'fr', 'es'] |
add_translations(key, dict) |
Add/update a key at runtime (thread-safe) | add_translations('hello', {'en': 'Hi'}) |
Create Your Translation File
Create a JSON file with any name you like (my_texts.json, lang.json, app_translations.json, etc.):
{
"app_title": {
"en": "My Application",
"fr": "Mon Application",
"es": "Mi Aplicación"
},
"login_button": {
"en": "Login",
"fr": "Connexion",
"es": "Iniciar sesión"
},
"welcome_user": {
"en": "Welcome {username}!",
"fr": "Bienvenue {username} !",
"es": "¡Bienvenido {username}!"
}
}
Then use it in your code:
import simple_localize
simple_localize.init_localizer('my_app_texts.json')
print(simple_localize.get_text('app_title'))
print(simple_localize.get_text('welcome_user', username="John"))
Thread Safety
set_language() applies per thread — each thread can have its own active language without affecting others. This makes it safe to use in web servers where each request runs in its own thread:
# Thread A (e.g. a French user's request)
simple_localize.set_language('fr')
simple_localize.get_text('welcome') # → French
simple_localize.get_text('goodbye') # → French too
# Thread B (e.g. a Spanish user's request), simultaneously
simple_localize.set_language('es')
simple_localize.get_text('welcome') # → Spanish, unaffected by Thread A
add_translations() is also thread-safe for concurrent writes.
Supported Languages
Add any languages you need! Use standard ISO 639-1 codes (en, fr, pt…) or regional variants (pt_br, pt_pt, en_us…).
The fallback chain for a pt_br user:
pt_br— exact matchpt— language fallback- default language (usually
en)
{
"hello": {
"pt_br": "Olá (Brasil)",
"pt_pt": "Olá (Portugal)",
"pt": "Olá",
"en": "Hello"
}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_localize-1.0.1.tar.gz.
File metadata
- Download URL: simple_localize-1.0.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03cf7b07f03e496dc4c3c6ded614fa556794aa629735817b71d3c800e1dc4652
|
|
| MD5 |
f7cd82348def7fd3c75660d1bbf766a0
|
|
| BLAKE2b-256 |
47b2c4b1edb309732dfb19d138d70b65057bca113d604fe1f3f515bf3f1ee4bc
|
Provenance
The following attestation bundles were made for simple_localize-1.0.1.tar.gz:
Publisher:
publish.yml on Thibault-Savenkoff/simple-localize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simple_localize-1.0.1.tar.gz -
Subject digest:
03cf7b07f03e496dc4c3c6ded614fa556794aa629735817b71d3c800e1dc4652 - Sigstore transparency entry: 1914530528
- Sigstore integration time:
-
Permalink:
Thibault-Savenkoff/simple-localize@047219a498437bb83b88f0146ad2d57c2f0e4660 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Thibault-Savenkoff
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@047219a498437bb83b88f0146ad2d57c2f0e4660 -
Trigger Event:
release
-
Statement type:
File details
Details for the file simple_localize-1.0.1-py3-none-any.whl.
File metadata
- Download URL: simple_localize-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1acf049f01b2ef3fe035202d6a706c6fee01adb7104624fa77186452a721b75d
|
|
| MD5 |
f0a3cade010075b52b73e69340a86fb5
|
|
| BLAKE2b-256 |
234bb0ebd67800d41c88833dcbced2ee92ec8720e5c97a779cd8cf6bf9c9308d
|
Provenance
The following attestation bundles were made for simple_localize-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on Thibault-Savenkoff/simple-localize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simple_localize-1.0.1-py3-none-any.whl -
Subject digest:
1acf049f01b2ef3fe035202d6a706c6fee01adb7104624fa77186452a721b75d - Sigstore transparency entry: 1914530860
- Sigstore integration time:
-
Permalink:
Thibault-Savenkoff/simple-localize@047219a498437bb83b88f0146ad2d57c2f0e4660 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Thibault-Savenkoff
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@047219a498437bb83b88f0146ad2d57c2f0e4660 -
Trigger Event:
release
-
Statement type: