Skip to main content

A fork of Plate (Internationalization library for Python), for YAML

Project description

YAML_Plate

A fork of Plate (Internationalization library for Python), for YAML

YAML Plate (YAML 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.

Full credits go to Dan and other contributors of the original Plate.

Features

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

Installing

$ pip3 install YAML-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 YAML files stored in a folder inside the application working directory and organized by their respective language codes. The YAML 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.yaml, it_IT.yaml, 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.yaml and it_IT.yaml
    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 yaml_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 MIT © 2021 Gegham Zakaryan

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

YAML_Plate-1.0.3.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

YAML_Plate-1.0.3-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

Details for the file YAML_Plate-1.0.3.tar.gz.

File metadata

  • Download URL: YAML_Plate-1.0.3.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.8.0 tqdm/4.46.1 CPython/3.8.5

File hashes

Hashes for YAML_Plate-1.0.3.tar.gz
Algorithm Hash digest
SHA256 e51698f743042523f8fd5c261318ddda65aaee663fbbeb28d7ba3ea484a45540
MD5 d7042198ae9c8d7d9829692d178de3e8
BLAKE2b-256 e41cf1ddcca99e18a2c193f8086f3617298f3e491f4961e9205de5dd2334931a

See more details on using hashes here.

File details

Details for the file YAML_Plate-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: YAML_Plate-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 37.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.8.0 tqdm/4.46.1 CPython/3.8.5

File hashes

Hashes for YAML_Plate-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5ecfaf10c7a86094087400204e78f1e77fa6317a9f3be30cb2792bf1f722027e
MD5 299de817a3fc1242fc22dff335079551
BLAKE2b-256 9a5f57412179434e8f665e08054ac13d6c625623a1c6135c0e20ad63f3739ff9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page