[Github](https://github.com/PearooXD/ezi18n) | [PyPI](https://pypi.org/project/ezi18n/)
--------
## 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
```py
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))
```
```json
{
"en": {
"dice_result": "Your dice rolled {dice}!"
},
"de": {
"dice_result": "Dein Würfel hat eine {dice} gewürfelt!"
}
}
```
-------
## Working with plurals
```py
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))
```
```json
{
"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.
Raw data
{
"_id": null,
"home_page": null,
"name": "ezi18n",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python, i18n, translation, localisation, localization",
"author": "Pearoo",
"author_email": "<contact@pearoo.hu>",
"download_url": "https://files.pythonhosted.org/packages/59/a2/5b1d82af659769b4d990facb8224a574c3cf222edd2b7a14bb7d62e1ea64/ezi18n-1.1.0.tar.gz",
"platform": null,
"description": "\n[Github](https://github.com/PearooXD/ezi18n) | [PyPI](https://pypi.org/project/ezi18n/)\n\n--------\n## Setting up\n Start by downloading the package via pip.\n ```\n python3 -m pip install ezi18n\n ```\n\n After that, you can just import it into your file.\n\n--------\n## Examples\n ```py\n import ezi18n\n import random\n \n _ = 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)\n dice = random.randint(1, 6)\n language = input(\"What's your native language? / Was ist Deine Muttersprache? (en/de) >>> \")\n \n print(_(\"dice_result\", language, dice=dice))\n ```\n ```json\n {\n \"en\": {\n \"dice_result\": \"Your dice rolled {dice}!\"\n },\n \"de\": {\n \"dice_result\": \"Dein W\u00fcrfel hat eine {dice} gew\u00fcrfelt!\"\n }\n }\n ```\n\n \n\n-------\n## Working with plurals\n ```py\n import ezi18n\n import locale\n \n _ = ezi18n.Translator(\"main\", \"_plurals\") # this will look for main_plurals.json as the language JSON file\n apples = int(input(\"How many apples do you have? >>> \"))\n language = locale.getlocale()[0][:2] # this will return the default OS language, such as en, hu, de, fr, es etc.\n \n print(_.one(\"apples\", apples, language, apples=apples))\n ```\n ```json\n {\n \"en\": {\n \"apples\": [\"You only have one apple! What a loser...\", \"You have {apples} apples!\"]\n },\n \"hu\": {\n \"apples\": [\"{apples} alm\u00e1d van!\"]\n }\n }\n ```\n\n This example does a great job at presenting how the `.one()` function works. Here's the explanation for the code:\n\n 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.\n\n 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.\n",
"bugtrack_url": null,
"license": null,
"summary": "A custom i18n implementation that is built to be easily used.",
"version": "1.1.0",
"project_urls": null,
"split_keywords": [
"python",
" i18n",
" translation",
" localisation",
" localization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ee56e40ad9fede0b1361a351dbda513f9bace05f5c598d4aa555db5135c12f07",
"md5": "9ec114ae2802d50c69bbd8ce06008b7e",
"sha256": "8a7ff424210d738c73773395d128ba7702f4a4302101899c7d82573b3cd41083"
},
"downloads": -1,
"filename": "ezi18n-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9ec114ae2802d50c69bbd8ce06008b7e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4766,
"upload_time": "2024-07-04T12:24:15",
"upload_time_iso_8601": "2024-07-04T12:24:15.587253Z",
"url": "https://files.pythonhosted.org/packages/ee/56/e40ad9fede0b1361a351dbda513f9bace05f5c598d4aa555db5135c12f07/ezi18n-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "59a25b1d82af659769b4d990facb8224a574c3cf222edd2b7a14bb7d62e1ea64",
"md5": "f3ecb242966345d56799f98e7bdeb804",
"sha256": "69767e6b371d7eecdf6719606b748b2c8ccfb449582fc024c68ed0f36cbed167"
},
"downloads": -1,
"filename": "ezi18n-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "f3ecb242966345d56799f98e7bdeb804",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4562,
"upload_time": "2024-07-04T12:24:17",
"upload_time_iso_8601": "2024-07-04T12:24:17.122335Z",
"url": "https://files.pythonhosted.org/packages/59/a2/5b1d82af659769b4d990facb8224a574c3cf222edd2b7a14bb7d62e1ea64/ezi18n-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-04 12:24:17",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "ezi18n"
}