l18n: Internationalization for pytz timezones and territories

2021.3 · maintenance · verified Sat Apr 11

l18n is a Python library providing internationalization (i18n) and localization (l10n) services specifically for `pytz` timezones and territory names. It offers lazy translations for names used for localization purposes, such as cities and full timezone names, by fetching them from the CLDR (Unicode's Common Locale Data Repository) database. The latest version, 2021.3, was released in November 2021. Its versioning strategy aims to align with `pytz` releases to ensure consistency with timezone names.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import `l18n`, set the desired language, and retrieve translated city and full timezone names using the `tz_cities` and `tz_fullnames` mappings.

import l18n
import os

# Set the language to French (for demonstration)
l18n.set_language('fr')

# Get translated city name for a timezone
easter_island_city_fr = l18n.tz_cities['Pacific/Easter']
print(f"Easter Island (French): {easter_island_city_fr}")

# Switch to English
l18n.set_language('en')

easter_island_city_en = l18n.tz_cities['Pacific/Easter']
print(f"Easter Island (English): {easter_island_city_en}")

# Get full translated timezone name
london_timezone_en = l18n.tz_fullnames['Europe/London']
print(f"London timezone (English): {london_timezone_en}")

l18n.set_language('de')
london_timezone_de = l18n.tz_fullnames['Europe/London']
print(f"London timezone (German): {london_timezone_de}")

view raw JSON →