Gettext usage with cariable in the middle of a sentence

Hey I would like gettext to translate this:

title = obj.title
gettext("Location and date for #{title} has changed!")

I tried this way already:

title = obj.title
gettext("Location and date for %{title} has changed!")

this way the msgids show up nicely, but the value never gets replaced

How can i make this work?

You need to pass substitutions as keyword list to the gettext function. It does not magically know about variables like #{} does.

title = obj.title
gettext("Location and date for %{title} has changed!", title: title)
4 Likes

oh, :blush: thanks!