[FIX] developer: adapt markup documentation
On how to combine Markup and translations Note that this does not work before 17.0 closes odoo/documentation#6189 Related: odoo/odoo#139316 Related: odoo/enterprise#49379 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
parent
ae05fe478d
commit
ff23483846
@ -418,9 +418,9 @@ the content (text).
|
||||
Markup('<R&D> <br/> <p>Hello</p>')
|
||||
>>> escape("<R&D>")
|
||||
Markup('<R&D>')
|
||||
>>> escape(_("List of Tasks on project %s: %s")) % (
|
||||
>>> _("List of Tasks on project %s: %s",
|
||||
... project.name,
|
||||
... Markup("<ul>%s</ul>") % Markup().join([Markup("<li>%s</li>") % t.name for t in project.task_ids])
|
||||
... Markup("<ul>%s</ul>") % Markup().join(Markup("<li>%s</li>") % t.name for t in project.task_ids)
|
||||
... )
|
||||
Markup('Liste de tâches pour le projet <R&D>: <ul><li>First <R&D> task</li></ul>')
|
||||
|
||||
@ -434,6 +434,22 @@ the content (text).
|
||||
>>> Markup(f"<p>Foo {self.bar}</p>") # bad, bar is inserted before escaping
|
||||
>>> Markup("<p>Foo {bar}</p>").format(bar=self.bar) # good, sorry no fstring
|
||||
|
||||
When working with translations, it is especially important to separate the HTML
|
||||
from the text. The translation methods accepts a :class:`~markupsafe.Markup`
|
||||
parameters and will escape the translation if it gets receives at least one.
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Markup("<p>%s</p>") % _("Hello <R&D>")
|
||||
Markup('<p>Bonjour <R&D></p>')
|
||||
>>> _("Order %s has been confirmed", Markup("<a>%s</a>") % order.name)
|
||||
Markup('Order <a>SO42</a> has been confirmed')
|
||||
>>> _("Message received from %(name)s <%(email)s>",
|
||||
... name=self.name,
|
||||
... email=Markup("<a href='mailto:%s'>%s</a>") % (self.email, self.email)
|
||||
Markup('Message received from Georges <<a href=mailto:george@abitbol.example>george@abitbol.example</a>>')
|
||||
|
||||
|
||||
Escaping vs Sanitizing
|
||||
----------------------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user