Gettext usage with cariable in the middle of a sentence

gettext
#1

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?

#2

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)
3 Likes
#3

oh, :blush: thanks!