Setting up
Start by downloading the package via pip.
python3 -m pip install ezi18n
After that, you can just import it into your file.
Examples
import ezi18n
import random
_ = ezi18n.Translator() # if you don't provide anything in the brackets, it will look for the file's name's language JSON file. If the main file is main.py, it will look for main_lang.json - unless you provide a base filename (in this case: main) and/or a suffix (by default: _lang)
dice = random.randint(1, 6)
language = input("What's your native language? / Was ist Deine Muttersprache? (en/de) >>> ")
print(_("dice_result", language, dice=dice))
{
"en": {
"dice_result": "Your dice rolled {dice}!"
},
"de": {
"dice_result": "Dein Würfel hat eine {dice} gewürfelt!"
}
}
Working with plurals
import ezi18n
import locale
_ = ezi18n.Translator("main", "_plurals") # this will look for main_plurals.json as the language JSON file
apples = int(input("How many apples do you have? >>> "))
language = locale.getlocale()[0][:2] # this will return the default OS language, such as en, hu, de, fr, es etc.
print(_.one("apples", apples, language, apples=apples))
{
"en": {
"apples": ["You only have one apple! What a loser...", "You have {apples} apples!"]
},
"hu": {
"apples": ["{apples} almád van!"]
}
}
This example does a great job at presenting how the .one() function works. Here's the explanation for the code:
The code will look for the default OS language, and will tell you how many apples you have with plurals in mind. I always get angry when I see "you have 1 apples"-ish text on a website, and it's an easy fix, but for some reason, many developers don't pay attention to it.
Hungarian doesn't make a difference between plurals, so the list for "hu"/"apples" only has 1 item. This won't be a problem though - the library isn't hardcoded to only look for the first and second elements in the returned list, it will look for the first and the last. Which means that if a list only has 1 item, it will only return that item.
Metadata
Release files for ezi18n 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ezi18n-1.1.0.tar.gz | 4.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ezi18n-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / ezi18n-1.1.0.tar.gz
| Download URL | ezi18n-1.1.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69767e6b371d7eecdf6719606b748b2c8ccfb449582fc024c68ed0f36cbed167
|
|
BLAKE2b-256 checksum How to use checksums |
59a25b1d82af659769b4d990facb8224a574c3cf222edd2b7a14bb7d62e1ea64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / ezi18n-1.1.0-py3-none-any.whl
| Download URL | ezi18n-1.1.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a7ff424210d738c73773395d128ba7702f4a4302101899c7d82573b3cd41083
|
|
BLAKE2b-256 checksum How to use checksums |
ee56e40ad9fede0b1361a351dbda513f9bace05f5c598d4aa555db5135c12f07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Security for ezi18n 1.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.