How do I override default date formats per locale in Django?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I override default date formats per locale in Django?

אורי
Django developers,

How do I override default date formats per locale in Django? I asked this question on Django Users and also Stack Overflow but I didn't receive any reply.

Is it possible to override these values at all?

Is it possible to define settings per language and how?



---------- Forwarded message ---------
From: אורי <[hidden email]>
Date: Wed, Jul 24, 2019 at 8:45 PM
Subject: How do I override default date formats per locale in Django?
To: <[hidden email]>


Hi,

We are using Django 1.11 for Speedy Net. I want to override the default values of DATE_FORMAT and MONTH_DAY_FORMAT in English, but keep the default values (or define them again) in Hebrew. So they will not be the same and will not be identical to Django's default values. In English we will have:

DATE_FORMAT = 'j F Y'
MONTH_DAY_FORMAT = 'j F'
YEAR_FORMAT = 'Y'

And in Hebrew:

DATE_FORMAT = 'j בF Y'
MONTH_DAY_FORMAT = 'j בF'

(and YEAR_FORMAT will be the same).

The template currently looks like this:

{% if can_view_profile and user.date_of_birth %}
    {% if can_view_dob_day_month or can_view_dob_year %}
        <tr>
            <th>{% if can_view_dob_day_month %}{% trans 'Birth Date' %}{% elif can_view_dob_year %}{% trans 'Birth Year' %}{% endif %}</th>
            <td>
                {% if can_view_dob_day_month and can_view_dob_year %}
                    {{ user.date_of_birth|date:settings.DATE_FORMAT }}
                {% elif can_view_dob_day_month %}
                    {{ user.date_of_birth|date:settings.MONTH_DAY_FORMAT }}
                {% elif can_view_dob_year %}
                    {{ user.date_of_birth|date:settings.YEAR_FORMAT }}
                {% endif %}
            </td>
        </tr>
    {% endif %}
{% endif %}

And I want it to display the dates in these formats in each language. How do I do it?

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CABD5YeF4-ETXDJsTt7o6%3DkgFrMkzgW%2BTbRofFVQz2gi9ua5Cig%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: How do I override default date formats per locale in Django?

Carlton Gibson-3


On 25 Jul 2019, at 16:09, ⁨אורי⁩ <⁨[hidden email]⁩> wrote:

I didn't receive any reply.

Even so, this isn’t really the place for a support question. Better to follow-up in the original locations with more details, in the attempt to prompt a response — oftentimes it’s just that the question needs more work to elicit a response.


Then return to SO or Django Users outlining exactly why what you tried from there isn’t working. 

Hopefully then you’ll get the help you need. 

Kind Regards,

Carlton

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/A189998E-C663-4A73-8730-575146D2D5E3%40gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: How do I override default date formats per locale in Django?

אורי
Thank you Carlton, I'll try it. I was not aware of the link you sent me.

On Thu, Jul 25, 2019 at 6:45 PM Carlton Gibson <[hidden email]> wrote:


On 25 Jul 2019, at 16:09, ⁨אורי⁩ <⁨[hidden email]⁩> wrote:

I didn't receive any reply.

Even so, this isn’t really the place for a support question. Better to follow-up in the original locations with more details, in the attempt to prompt a response — oftentimes it’s just that the question needs more work to elicit a response.


Then return to SO or Django Users outlining exactly why what you tried from there isn’t working. 

Hopefully then you’ll get the help you need. 

Kind Regards,

Carlton

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/A189998E-C663-4A73-8730-575146D2D5E3%40gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CABD5YeEXX-Y7E5VUvh09BjV-4hM_ng1iY%2By440EkddzAi0-Mhw%40mail.gmail.com.