{"repo":"boardpack/pydantic-i18n","free":true,"listed":false,"github":"https://github.com/boardpack/pydantic-i18n","clone":"git clone https://github.com/boardpack/pydantic-i18n.git","description":"pydantic-i18n is an extension to support an i18n for the pydantic error messages.","language":"Python","stars":101,"topics":["translation","i18n","internationalization","python","pydantic","fastapi"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"pydantic-i18n is an extension to support an i18n for the pydantic error messages. --- Documentation : https://pydantic-i18n.boardpack.org Source Code : https://github.com/boardpack/pydantic-i18n --- Requirements Python 3.8+ pydantic-i18n has the next dependencies: Pydantic Babel Installation First steps To start to work with pydantic-i18n, you can just create a dictionary (or create any needed translations storage and then convert it into dictionary) and pass to the main PydanticI18n class. To translate messages, you need to pass result of exception.errors() call to the translate method: (This script is complete, it should run \"as is\" for Pydantic 2+, an example for Pydantic 1 is here) In the next chapters, you will see current available loaders and how to implement your own loader. Usage with FastAPI Here is a simple example usage with FastAPI. Create it Let's create a tr.py file: 11-20 : As you see, we selected the simplest variant to store translations, you can use any that you need. 23-24 : To not include locale query parameter into every handler, we created a simple function get locale , which we will include as a global dependency with Depends . 29-36 : An example of overridden function to return translated messages of the validation exception. Now we are ready to create a FastAPI application: 8 : Add get locale function as a global dependency. !!! note If you need to use i18n only for specific part of your application, you can add this get locale function to the specif","default_branch":null,"files":null,"tree":[],"storefront":"/r/boardpack","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/boardpack/pydantic-i18n/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}