Open Garito opened 1 month ago
The other way of writing it looks good if supported...
from fastapi_babel.core import lazy_gettext as _l
_l("Not support type: {mytype}").format(mytype=cls._type)
But I got an error:
AttributeError: '__LazyText' object has no attribute 'format'
Add one thing: gettext supports format but lazy_gettext does not, I think it should have methods supported by string objects, otherwise it would be weird.
In my mind, fastapi-babel should mimick pybabel as much as possible, otherwise should not be called fastapi-babel
In my mind, fastapi-babel should mimick pybabel as much as possible, otherwise should not be called fastapi-babel
Is it better to mimic babel/python's original gettext? And not pybabel?
python gettext doesn't allow placeholders and, with fastapi-babel, one expects the pybabel api integrated as well as possible with fastapi, no?
@Garito
Python gettext doesn't allow placeholders and, with fastapi-babel, one expects the pybabel API integrated as well as possible with fastapi, no?
I agree with you but we have to consider backend ecosystems like databases, forms, views, templates, and so on. so we have to make some APIs that work well with pybabel and Fastapi. I am working on some issues that handle all conflicts.
The other way of writing it looks good if supported...
from fastapi_babel.core import lazy_gettext as _l _l("Not support type: {mytype}").format(mytype=cls._type)
But I got an error:
AttributeError: '__LazyText' object has no attribute 'format'
Add one thing: gettext supports format but lazy_gettext does not, I think it should have methods supported by string objects, otherwise, it would be weird.
LazyGettext is not the main gettext, It's only a wrapper around the gettext object that when we need to apply translation texts into params without calling them explicitly like database orm fields, Wtform model fields, and ...
so you cannot merge these two approaches and invoke them directly from the initialized object.
for example:
from fastapi_babel.core import lazy_gettext as _
class Model(BaseModel):
text: str = Field(default=_("Write what you want")
model = Model() model.text.format()
Hi! In pybabel you could use _("$(name)s's house", name = "Garito") Whould be nice to have it here
Thanks!
the best approach is:
name = "Parsa"
welcome_text = _("Welcome %s" % name)
If this works well with po editors and allows the normal string formatting, would be good for my part
Hi! In pybabel you could use _("$(name)s's house", name = "Garito") Whould be nice to have it here
Thanks!