ezi18n


Nameezi18n JSON
Version 1.0.3 PyPI version JSON
download
home_page
SummaryA custom i18n implementation that is built to be easily used.
upload_time2023-11-30 14:51:04
maintainer
docs_urlNone
authorPearoo
requires_python
license
keywords python i18n translation localisation localization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
[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": "",
    "name": "ezi18n",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,i18n,translation,localisation,localization",
    "author": "Pearoo",
    "author_email": "<contact@pearoo.hu>",
    "download_url": "https://files.pythonhosted.org/packages/ea/be/bf0ea6080b360cac597b1a81fe92713cb527cc1b07fbee6d33356fe7c6e2/ezi18n-1.0.3.tar.gz",
    "platform": null,
    "description": "\r\n[Github](https://github.com/PearooXD/ezi18n) | [PyPI](https://pypi.org/project/ezi18n/)\r\n\r\n\r\n\r\n--------\r\n\r\n## Setting up\r\n\r\n Start by downloading the package via pip.\r\n\r\n ```\r\n\r\n python3 -m pip install ezi18n\r\n\r\n ```\r\n\r\n\r\n\r\n After that, you can just import it into your file.\r\n\r\n\r\n\r\n--------\r\n\r\n## Examples\r\n\r\n ```py\r\n\r\n import ezi18n\r\n\r\n import random\r\n\r\n \r\n\r\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)\r\n\r\n dice = random.randint(1, 6)\r\n\r\n language = input(\"What's your native language? / Was ist Deine Muttersprache? (en/de) >>> \")\r\n\r\n \r\n\r\n print(_(\"dice_result\", language, dice=dice))\r\n\r\n ```\r\n\r\n ```json\r\n\r\n {\r\n\r\n    \"en\": {\r\n\r\n        \"dice_result\": \"Your dice rolled {dice}!\"\r\n\r\n    },\r\n\r\n    \"de\": {\r\n\r\n        \"dice_result\": \"Dein W\u00fcrfel hat eine {dice} gew\u00fcrfelt!\"\r\n\r\n    }\r\n\r\n }\r\n\r\n ```\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n-------\r\n\r\n## Working with plurals\r\n\r\n ```py\r\n\r\n import ezi18n\r\n\r\n import locale\r\n\r\n \r\n\r\n _ = ezi18n.Translator(\"main\", \"_plurals\") # this will look for main_plurals.json as the language JSON file\r\n\r\n apples = int(input(\"How many apples do you have? >>> \"))\r\n\r\n language = locale.getlocale()[0][:2] # this will return the default OS language, such as en, hu, de, fr, es etc.\r\n\r\n \r\n\r\n print(_.one(\"apples\", apples, language, apples=apples))\r\n\r\n ```\r\n\r\n ```json\r\n\r\n {\r\n\r\n     \"en\": {\r\n\r\n         \"apples\": [\"You only have one apple! What a loser...\", \"You have {apples} apples!\"]\r\n\r\n     },\r\n\r\n     \"hu\": {\r\n\r\n         \"apples\": [\"{apples} alm\u00e1d van!\"]\r\n\r\n     }\r\n\r\n }\r\n\r\n ```\r\n\r\n\r\n\r\n This example does a great job at presenting how the `.one()` function works. Here's the explanation for the code:\r\n\r\n\r\n\r\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.\r\n\r\n\r\n\r\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.\r\n\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A custom i18n implementation that is built to be easily used.",
    "version": "1.0.3",
    "project_urls": null,
    "split_keywords": [
        "python",
        "i18n",
        "translation",
        "localisation",
        "localization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "841f8330450f5dd03f45be78ec172a9c2ed2fc28f82e0324dffe60da32486cd0",
                "md5": "7d6133d2974e1f8331f339971b684d58",
                "sha256": "fb302349bd8d9586afe3c9a5b4fe65f2c08f28346492130c21c1ea99fce09558"
            },
            "downloads": -1,
            "filename": "ezi18n-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7d6133d2974e1f8331f339971b684d58",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4713,
            "upload_time": "2023-11-30T14:51:03",
            "upload_time_iso_8601": "2023-11-30T14:51:03.381019Z",
            "url": "https://files.pythonhosted.org/packages/84/1f/8330450f5dd03f45be78ec172a9c2ed2fc28f82e0324dffe60da32486cd0/ezi18n-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eabebf0ea6080b360cac597b1a81fe92713cb527cc1b07fbee6d33356fe7c6e2",
                "md5": "a77583a6e5fe3a60de2e2f8f1bb6a5a8",
                "sha256": "f4cf4d61140d73e284b5474df7626d85cc5a2be63509eefd28443f014f7fb883"
            },
            "downloads": -1,
            "filename": "ezi18n-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "a77583a6e5fe3a60de2e2f8f1bb6a5a8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4718,
            "upload_time": "2023-11-30T14:51:04",
            "upload_time_iso_8601": "2023-11-30T14:51:04.863725Z",
            "url": "https://files.pythonhosted.org/packages/ea/be/bf0ea6080b360cac597b1a81fe92713cb527cc1b07fbee6d33356fe7c6e2/ezi18n-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-30 14:51:04",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ezi18n"
}
        
Elapsed time: 0.15283s