Welcome | Get started | Dive into Lino | Contribute | Reference


The lazy_format() function

Lino has a function lino.core.utils.lazy_format() which we sometimes use. Here is an example.

>>> from lino import startup
>>> startup('lino_book.projects.min2.settings.demo')
>>> from lino.core.utils import lazy_format
>>> from lino.api import dd, rt, _
>>> M = rt.models.cal.Event
>>> s = lazy_format(
...   _("Only for {model} instances."),
...   model=M._meta.verbose_name)
>>> print(s)
Only for Calendar entry instances.
>>> with dd.translation.override('de'):
...     print(s)
Only for Kalendereintrag instances.

Note that we care only for the "Calendar entry" text. The surrounding text Only for {model} instances. is not translated to German because it is a fictive example of a translatable string for which there is no translation.

See also :djangoticket`14174`.