Opened 2 years ago
Last modified 13 months ago
#35333 assigned Bug
Template tag `unlocalize` does not work with `date` and `time` filters.
| Reported by: | Natalia Bidart | Owned by: | Ahmed Nassar |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
Following #35306, it was noticed that using the date or time template filters would not honor the unlocalize template tag. See regression tests:
-
tests/i18n/tests.py
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 355505a10d..90cf4630bf 100644
a b class FormattingTests(SimpleTestCase): 1351 1351 self.assertEqual(template2.render(context), output2) 1352 1352 self.assertEqual(template3.render(context), output3) 1353 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1354 1400 def test_localized_off_numbers(self): 1355 1401 """A string representation is returned for unlocalized numbers.""" 1356 1402 template = Template(
Change History (6)
comment:1 by , 2 years ago
comment:2 by , 2 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
comment:3 by , 15 months ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:4 by , 15 months ago
I'd like to work on this issue if it's still available. Could you confirm if it's unassigned? If so, I will start by reviewing the expected behavior and checking the existing implementation of date and time filters.
Looking forward to contributing!
comment:5 by , 14 months ago
| Has patch: | set |
|---|
comment:6 by , 13 months ago
| Patch needs improvement: | set |
|---|
Note:
See TracTickets
for help on using tickets.
I'm not yet sure if this can be resolved in the code, or if we should rather complement the template filter docs, telling that if you apply an l10n-sensible filter inside an unlocalized section, you should specify an explicit format argument. The problem being that the way filters are currently implemented, it's not possible to transmit any context. That explains for example that
floatformatgained anuparameter to force unlocalization (see #30086).So in your example in the tests above, you should use
|date:settings.DATE_FORMATand not justDATE_FORMAT. Thoughts?