Wednesday, October 28, 2015

Re: IntComma without RequestContext

Thank you. Knew I was missing something easy.



On Tuesday, October 27, 2015 at 8:54:08 PM UTC-4, foobar wrote:
Your language string is backwards:

>>> activate("en-us")
>>> intcomma(1000)
'1,000'

>>> activate("en")
>>> intcomma(1000)
'1,000'


use_l10n=False in a template is:

{% load l10n %}

{% localize off %}
    {{ value }}
{% endlocalize %}

https://docs.djangoproject.com/en/1.8/topics/i18n/formatting/#localize

2015-10-28 1:37 GMT+02:00 Michael Newman <newma...@gmail.com>:
> I am feeling a little lost, a project that I have used intcomma in reliably
> on an update suddenly stopped getting the commas inserted. This is for an
> out of request cycle email.
>
> Attempting activate the language doesn't seem to change anything. Am I
> missing something simple here?
>
>>>> from django.contrib.humanize.templatetags.humanize import intcomma
>>>> intcomma(1000)
> u'1000'
>>>> intcomma("1000", use_l10n=False) #not sure how to do this in templates
> u'1,000'
>>>> from django.utils.translation import activate, get_language
>>>> get_language()
> u'us-en'
>>>> activate("us-en")
>>>> intcomma("1000")
> u'1000'
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/30892a71-1a41-488e-b9f9-3d71cfc6abcb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/23d9828c-f1ab-425a-9fe3-49e0703a542c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment