Skip to main content

pydantic-translations

Translations for pydantic errors.

Languages

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!

Installation

python3 -m pip install pydantic-translations

Usage

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'}

Custom translations

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)

Contributors

  1. The original error messages provided by @samuelcolvin and pydantic contributors.
  2. The Russian translation is provided by @orsinium.
  3. The German, Spanish, French, Italian, and Dutch translations are provided by Andovar translation agency.

Minor corrections and improvements are provided by the project contributors.

Release files for pydantic-translations 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-translations 0.4.2
File Size Uploaded
pydantic_translations-0.4.2.tar.gz 39.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-translations 0.4.2
File Interpreter ABI Platform
pydantic_translations-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 75.7 kB

Release files / pydantic_translations-0.4.2.tar.gz

Download URL pydantic_translations-0.4.2.tar.gz
Size 39.3 kB
Tags Source
SHA-256 checksum
How to use checksums
caf62e1a3d0cb8547f6eb525476c32141d0aec2714c19d6278479cac632b1590
BLAKE2b-256 checksum
How to use checksums
6d83df0eff22b92bbe51faa6c06cca4d0a7be1d4e247967a0a61ca234f32a531
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / pydantic_translations-0.4.2-py3-none-any.whl

Download URL pydantic_translations-0.4.2-py3-none-any.whl
Size 36.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
685a73fa3fb837947fa5d20ff019c3321abe1d652a1a73022e333667cad5fd76
BLAKE2b-256 checksum
How to use checksums
f89ad1be7dd59369a5292690db4f3440c629b24aac7f83caf44cf0cebc4c3442
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page