boardpack / pydantic-i18n

pydantic-i18n is an extension to support an i18n for the pydantic error messages.
https://pydantic-i18n.boardpack.org
MIT License
83 stars 11 forks source link

Key's ending after placeholders is not matched #160

Closed niqzart closed 8 months ago

niqzart commented 1 year ago

Description

In keys with placegholders the remaining part after placeholders is not used to find the key, witch leads to unusable keys, like ensure that there are no more than {} digits in total

To Reproduce

from decimal import Decimal
from pydantic import BaseModel, Field

class T(BaseModel):
    t: Decimal = Field(max_digits=3)

tr = PydanticI18n({"en_US": {"ensure that there are no more than {} digits in total": "something {} something"}})
try:
    T(t="1111")
except Exception as e:
    print(tr.translate(e.errors(), locale=tr.default_locale))

Expected result: something 3 something Real result: ensure that there are no more than 3

Environment

Additional Details

I think I figured out what is wrong, I will be submitting a PR to fix this soon