Issue #99 open

can we use new string formatting using .format() method?

Thomas Waldmann
repo owner created an issue

moin stil uses "%s %d" % (foo, bar) style string formatting.

some work has already been done on replacing this with .format() new style formatting, but it is not completed yet.

especially, a lot of translatable strings still use old %-style.

maybe this is related to the _() method there, this should be checked (and whether we can / should use .format() there.

this needs to be done before doing translations, because change of original english strings would make the translated string invalid.

if we decide on using some other formatting method than now, the respective refactoring should be done globally in the source.

Comments (4)

  1. Julian Brost

    If you look at the gettext implementation of flask-babel, you can see that it just formats the translated string using the % syntax, nothing fancy there.

    Without patching flask-babel, it would be possible to do something like

    _('Good morning, {}!').format('Joe')
    

    but of course it would be much nicer if one could do the same thing like this:

    _('Good morning, {}!', 'Joe')
    

    I don't know if there's a specific reason for this or if it is just out of habit.

    [1] https://github.com/mitsuhiko/flask-babel/blob/master/flaskext/babel.py#L447

  2. Log in to comment