3

I'm trying to do something like this:

${_('Hello ${name}, welcome to...', mapping=dict(name='${name}'))}

Where _() is my Babel translation function, the first ${name} is string interpolation I'd like to be performed by Babel and the second ${name} I'd like to be replaced by Mako so the value is the value in the Python dictionary:

This is ultimately rendered as:

Hello ${name}, welcome to...

Not desirable. Problem seems to be that since the second ${name} is nested inside another ${}, it's not evaluated.

What I'm aiming for:

Hello Ryan, welcome to...

How can I achieve this?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
ryonlife
  • 6,563
  • 14
  • 51
  • 64

1 Answers1

3

Why not use Python's string formatting?

${ _('Hello {name}, welcome to ...').format(name=name) }
tuomur
  • 6,888
  • 34
  • 37