@@ -275,21 +275,35 @@ above.
275275Attributes
276276~~~~~~~~~~
277277When rendering UI elements, it's handy to have a single translation that
278- contains everything you need in one variable. For example, a Web
279- Component confirm window with an OK button, a Cancel button, and a
280- message .
278+ contains everything you need in one variable. For example, a HTML
279+ form input may have a value, but also a placeholder attribute, aria-label
280+ attribute, and maybe a title attribute .
281281
282282.. code-block :: python
283283 >> > l10n = DemoLocalization("""
284- ... order-cancel-window = Are you sure you want to cancel the order #{ $order }?
285- ... .ok = Yes
286- ... .cancel = No
284+ ... login-input = Predefined value
285+ ... .placeholder = { $email }
286+ ... .aria-label = Login input value
287+ ... .title = Type your login email
287288 """ )
288- >> > message, attributes = l10n.format_message(" order-cancel-window" , {' order' : 123 })
289+ >> > message, attributes = l10n.format_message(
290+ " login-input" , {" placeholder" : " email@example.com" }
291+ )
289292 >> > message
290- ' Are you sure you want to cancel the order #123? '
293+ ' Predefined value '
291294 >> > attributes
292- {' ok' : ' Yes' , ' cancel' : ' No' }
295+ {' placeholder' : ' email@example.com' , ' aria-label' : ' Login input value' , ' title' : ' Type your login email' }
296+
297+ You can also use the formatted message without unpacking it.
298+
299+ .. code-block :: python
300+ >> > fmt_msg = l10n.format_message(
301+ " login-input" , {" placeholder" : " email@example.com" }
302+ )
303+ >> > fmt_msg.message
304+ ' Predefined value'
305+ >> > fmt_msg.attributes
306+ {' placeholder' : ' email@example.com' , ' aria-label' : ' Login input value' , ' title' : ' Type your login email' }
293307
294308 Known limitations and bugs
295309~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments