Skip to content

Pass extra args to babel functions (decimal_quantization) #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wjdp opened this issue Jul 31, 2018 · 2 comments
Closed

Pass extra args to babel functions (decimal_quantization) #142

wjdp opened this issue Jul 31, 2018 · 2 comments

Comments

@wjdp
Copy link

wjdp commented Jul 31, 2018

Babel have added decimal_quantization to format_decimal, format_currency, format_percent, and format_scientific. Flask-Babel cannot pass this arg through when using the equivalent proxy functions so users cannot use these new features.

For reference here is Flask-Babel's format_percent

def format_percent(number, format=None):
    """Return formatted percent value for the locale in request

    :param number: the number to format
    :param format: the format to use
    :return: the formatted percent number
    :rtype: unicode
    """
    locale = get_locale()
    return numbers.format_percent(number, format=format, locale=locale)

And the signature of the underlying Babel function:

def format_percent(number, format=None, locale=LC_NUMERIC, decimal_quantization=True):

Should Flask-Babel hard code args in like this, or should it use the *args, **kwargs pattern to pass through extra args to the underlying Babel functions?

@TkTech
Copy link
Contributor

TkTech commented Aug 1, 2018

A great many of these methods are just dumb wrappers around the babel method, passing the locale and the rest unchanged. I've been contemplating some alternatives to prevent us from having to maintain them. We could reflect all of the flask-babel bindings, checking the signature (inspect.getargspec/inspect.signature) of the babel method to see if it takes a locale kwarg and fetching it if so.

@TkTech
Copy link
Contributor

TkTech commented Feb 25, 2020

Removing this method in favor of direct imports from babel in v2. See #164.

@TkTech TkTech closed this as completed Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants