Skip to main content

Plate

Internationalization Library for Python

Plate (Python translate) is an i18n library for Python that gives your application the ability to speak many languages. It is designed to be simple and straightforward to use for developers and easy for translators.

Features

  • Translations based on JSON files
  • Interpolated translations
  • Pluralization
  • Emoji

Installing

$ pip3 install plate

Setup

Plate is not going to perform any translation; what it does, instead, is simply providing a way to manage already-translated phrases so that they can be easily accessed from your application code.

These translated phrases are kept in JSON files stored in a folder inside the application working directory and organized by their respective language codes. The JSON keys are in common to all translations and the values of each contain the translated phrases.

  1. Create a new locales folder in your working directory to store translation files.
  2. Put files named after their language codes: en_US.json, it_IT.json, and so on. All available language codes can be found here.
  3. Start adding new phrases and translations. Here's an example for en_US.json and it_IT.json
    {
        "hello": "Hello", 
        "morning": "Good morning, {name}",
        "drink": "Let's drink :SAKE: together",
        "apples": "No apples | One apple | {count} apples"
    }
    
    {
        "hello": "Ciao", 
        "morning": "Buongiorno, {name}",
        "drink": "Beviamo :SAKE: insieme",
        "apples": "Nessuna mela | Una mela | {count} mele"
    }
    

Usage

Instantiation

First of all, create a new Plate instance. Plate will automatically look for files inside the locales folder or another custom folder you pass to the root parameter. The default and the fallback locale is en_US, by default.

from plate import Plate

plate = Plate()

Translation

Translate a phrase by simply passing a key and a language code of the destination locale.

plate("hello", "it_IT")  # Ciao

You can also set a new default locale to have all subsequent translations in that language.

plate.set_locale("it_IT")
plate("hello")  # Ciao

Or, get a translator for a given locale instead, so that the default locale will be kept unchanged.

italian = plate.get_translator("it_IT")
italian("hello")  # Ciao

Note: The examples below will assume plate.set_locale("it_IT") for conciseness.

Interpolation

Pass named arguments to interpolate your translations.

plate("morning", name="Dan")  # Buongiorno, Dan

Emoji

Emoji can be added with :EMOJI_NAME: inside your sources and are automatically inserted with the actual values. All available emoji can be found here. You can search for, visualize them and grab their names at https://emojipedia.org/.

plate("drink")  # Beviamo 🍶 insieme

Pluralization

Pluralization is done by keeping all the plural cases separated by a pipe | (by default, customizable) and by using the special interpolation key {count}. The following example shows how to translate and pluralize a phrase for count cases of zero, one and more.

plate("apples", count=0)  # Nessuna mela
plate("apples", count=1)  # Una mela
plate("apples", count=7)  # 7 mele

License

MIT © 2020 Dan

Release files for Plate 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 Plate 1.0.1
File Size Uploaded
Plate-1.0.1.tar.gz 37.6 kB Details

Built distribution (wheel)

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

Total release size: 76.1 kB

Release files / Plate-1.0.1.tar.gz

Download URL Plate-1.0.1.tar.gz
Size 37.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f2e3b7960c310379745c7ea1f4fce00b6e6c25041e1838cb81b1310c8af74dc0
BLAKE2b-256 checksum
How to use checksums
fc913a9236bded434ce8b223bf4e818ee811999f75afde3e5bd80b82acc00c45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

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

Download URL Plate-1.0.1-py3-none-any.whl
Size 38.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5ee257cbe11790f5c4b0426f05ea9c734ad14d4ae27187c3e52d1ccce2ad042
BLAKE2b-256 checksum
How to use checksums
a91e6eb7cde44038a40fed11c270aae099b9e949f75ea39abbcec11418d90027
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

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