
Security News
Node.js Moves Toward Stable TypeScript Support with Amaro 1.0
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
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.
$ pip3 install plate
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.
locales
folder in your working directory to store translation files.en_US.json
, it_IT.json
, and so on. All available language codes can
be found here.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"
}
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()
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.
Pass named arguments to interpolate your translations.
plate("morning", name="Dan") # Buongiorno, Dan
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 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
MIT © 2020 Dan
FAQs
Internationalization Library for Python
We found that Plate demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.