I'm trying to set up the formatting of dates in templates based on a locale supplied by the user. As the rest of the page will remain in the original local ('en'), I only want my users' supplied data to be formatted.
for example, dates.
users in the uk should be able to use l10n on the dates on their pages, but I don't want to set the whole site to be en_GB.
is there a way to set the locale in a template within a block, eg. something like
{% locale|'en_GB' %}
{{ my_date|localize }}
{% endlocale %}
You don't need to do anything explicit in the template.
Inside your
settings.pydefine theFORMAT_MODULE_PATHsetting. Like:under the
formatsdirectory create one python package per supported language(other than your default) of your project. Inside each of these you should have aformats.pywhich should have any localized formatting options.In my case the default language for my project is
en, but I also supportel(greek). So I have this in mysettings.py:Inside the
myproject/websiteapp/formatsdirectory I have aelpackage with aformats.pyfile, like:Inside the
formats.pyI have this:which is the greek specific representation of a date.
So when I use a datetime field inside my templates:
It prints the default
enrepresentation when locale is set to the default:and my custom greek one when the locale is set to
el.More info here
Edit
Hmm, I just realized that you asked for specific template blocks or values. Maybe the localize template filter or the localize template tag are more relevant to your specific case?