from django.utils.translation import ugettext_lazy as _
_(u"I am off to school at '%s' o'clock" % time)
This is kind of odd, since I would get a whole line to translate like this
"I am off to school at \'%s\' o'clock"
Now if the translator removes the \’%s\’ by mistake, it would break the code.
Should I better separate the sentence into two parts? But this might give the translator trouble to understand the context of the sentence.
_(u"I am off to school at ") + '%s' + _(u"o'clock") % time
Is there a better approach to this?
If you make use of named string interpolation as opposed to positional string interpolation, this should protect you from an exception if the translator forgets one of the parameters from his translated string.
An example from the django docs:
Note the dictionary of {‘name’: ‘value’} pairs to be used in string substitution.
(django docs)