I am learning Django's ways of doing internationalization and localization. To do so, I am following this tutorial:
The issue I have encountered is that the test the tutorial proposes is not working. Furthermore, I cannot see how it could ever have worked.
Here is the relevant template bit
<div class="row">
<div class="col-md-4">
<h2 id="local-date">{{today}}</h2>
<p>This is the time using your local information. </p>
<p><a class="btn btn-default" href="#" role="button">View details »</a></p>
</div>
<div class="col-md-4">
<h2 id="non-local-date">{{today|unlocalize}}</h2>
<p>This is the default time format. </p>
<p><a class="btn btn-default" href="#" role="button">View details »</a></p>
</div>
The view is as follows
from django.shortcuts import render
import datetime
def home(request):
today = datetime.date.today()
return render(request, "taskbuster/index.html", {'today': today})
The test is below
def test_localization(self):
today = date.today()
for lang in ['en', 'ca']:
activate(lang)
self.browser.get(self.get_full_url("home"))
local_date = self.browser.find_element_by_id("local-date")
non_local_date = self.browser.find_element_by_id("non-local-date")
self.assertEqual(formats.date_format(today, use_l10n=True),
local_date.text)
self.assertEqual(today.strftime('%Y-%m-%d'), non_local_date.text)
The failure I am seeing is
self.assertEqual(today.strftime('%B %d, %Y'), non_local_date.text)
AssertionError: 'June 22, 2019' != 'jun. 22, 2019'
- June 22, 2019
? ^ ^
+ jun. 22, 2019
? ^ ^
As you can see, the Catalan version is not the same as the default non-localized version. Am I missing something obvious here? Has something changed with the way these bits work in Django that creates this failure? The author of the tutorial claims that this test should pass at this point in the tutorial.
P.S. If one adds other, more interesting languages in which there is a more logical day->month->year format for displaying dates, he can observe that failure as well. Consider the case of ru
:
AssertionError: '22 June, 2019' != 'Июнь 22, 2019'
- 22 June, 2019
+ Июнь 22, 2019