Skip to main content

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:

  1. pt_br — exact match
  2. pt — language fallback
  3. default language (usually en)
{
  "hello": {
    "pt_br": "Olá (Brasil)",
    "pt_pt": "Olá (Portugal)",
    "pt": "Olá",
    "en": "Hello"
  }
}

Release files for simple-localize 1.0.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 simple-localize 1.0.1
File Size Uploaded
simple_localize-1.0.1.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple-localize 1.0.1
File Interpreter ABI Platform
simple_localize-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / simple_localize-1.0.1.tar.gz

Download URL simple_localize-1.0.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
03cf7b07f03e496dc4c3c6ded614fa556794aa629735817b71d3c800e1dc4652
BLAKE2b-256 checksum
How to use checksums
47b2c4b1edb309732dfb19d138d70b65057bca113d604fe1f3f515bf3f1ee4bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.

Transparency log

Release files / simple_localize-1.0.1-py3-none-any.whl

Download URL simple_localize-1.0.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1acf049f01b2ef3fe035202d6a706c6fee01adb7104624fa77186452a721b75d
BLAKE2b-256 checksum
How to use checksums
234bb0ebd67800d41c88833dcbced2ee92ec8720e5c97a779cd8cf6bf9c9308d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

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