Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
pydantic-translations
Advanced tools
Translations for pydantic errors.
Currently, we have translated pydantic v1.10.2 errors to the following languages:
de
: German. 87/87.es
: Spanish. 87/87.fr
: French. 87/87.it
: Italian. 87/87.nl
: Dutch. 87/87.ru
: Russian. 82/87.Need more languages? Contributions are welcome!
python3 -m pip install pydantic-translations
Let's say you have a pydantic model User
:
from pydantic import BaseModel
class User(BaseModel):
age: int
The translations are managed by the Translator
class that is instantiated with the locale (language) you want the messages to be translated to:
from pydantic_translations import Translator
tr = Translator('ru')
You can use translator as a context manager to translate pydantic exceptions raised from the context:
with tr:
User.parse_obj({'age': 'idk'})
# ValidationError: 1 validation error for User
# age
# значение должно быть целым числом (type=type_error.integer)
Or use the translate_exception
method to directly translate an exception instance:
from pydantic import ValidationError
try:
User.parse_obj({'age': 'idk'})
except ValidationError as exc:
exc = tr.translate_exception(exc)
raise exc
Or use the translate_error
method to translate a specific error:
try:
User.parse_obj({'age': 'idk'})
except ValidationError as exc:
err = exc.errors()[0]
err = tr.translate_error(err)
print(err)
# {'loc': ('age',), 'msg': 'значение должно быть целым числом', 'type': 'type_error.integer'}
If you have translated the errors to a new language, the best you can do is contribute it back here. If, for some (legal?) reason, you can't, you may pass into the Translated as a locale a l10n locale with your translations:
from l10n import Locales
locales = Locales()
locale = locales['ua']
tr = Translator(locale)
Minor corrections and improvements are provided by the project contributors.
FAQs
Translations for pydantic errors.
We found that pydantic-translations 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.