python-babel / flask-babel

i18n and l10n support for Flask based on Babel and pytz
https://python-babel.github.io/flask-babel/
Other
432 stars 159 forks source link

Add more format support like *args #220

Open betterlch opened 1 year ago

betterlch commented 1 year ago

like this:

def gettext(string, *args, **variables):
    """
        gettext(u'Hello World!')
        gettext(u'Hello %(name)s!', name='World')
        gettext(u'Hello %s!', 'World')
    """
    t = get_translations()
    if t is None:
        return string if not variables else string % variables
    s = t.ugettext(string)
    if args:
        return s % args
    else:
        return s if not variables else s % variables
betterlch commented 1 year ago

Also,add "{}".format(*args) support in the same way, it's easy to write the code and tests.

betterlch commented 1 year ago

like #170 maybe add a new func name fgettext to support format is better than changing func gettext