Skip to content

Commit a5c31f9

Browse files
lb-laymonage
authored andcommitted
Mark js_translation_strings template tag for deprecation
- `js_translation_strings` is no longer used by Wagtail admin code - It was historically used for generating the JS config strings within templates, we now do this in Python and expose as JSON via the `wagtail_config` template tag - Add a warning for deprecation so that we can remove this unused template tag in the next major version of Wagtail - See wagtail#9771 for context
1 parent 53f55a8 commit a5c31f9

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Changelog
5151
* Maintenance: Ensure the side panel's show event is dispatched after any hide events (Sage Abdullah)
5252
* Maintenance: Migrate preview-panel JavaScript to Stimulus & TypeScript, add full unit testing (Sage Abdullah)
5353
* Maintenance: Move `wagtailConfig` values from inline scripts to the `wagtail_config` template tag (LB (Ben) Johnston, Sage Abdullah)
54+
* Maintenance: Deprecate the `{% locales %}` and `{% js_translation_strings %}` template tags (LB (Ben) Johnston, Sage Abdullah)
5455

5556

5657
6.2.2 (24.09.2024)

docs/releases/6.3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ This release adds formal support for Django 5.1.
7373
* Ensure the side panel's show event is dispatched after any hide events (Sage Abdullah)
7474
* Migrate preview-panel JavaScript to Stimulus & TypeScript, add full unit testing (Sage Abdullah)
7575
* Move `wagtailConfig` values from inline scripts to the `wagtail_config` template tag (LB (Ben) Johnston, Sage Abdullah)
76+
* Deprecate the `{% locales %}` and `{% js_translation_strings %}` template tags (LB (Ben) Johnston, Sage Abdullah)
7677

7778

7879
## Upgrade considerations - changes affecting all projects
@@ -98,3 +99,9 @@ To disable the automatic preview update feature, set [`WAGTAIL_AUTO_UPDATE_PREVI
9899
The undocumented `locales` template tag will be removed in a future release.
99100

100101
If access to JSON locales within JavaScript is needed, use `window.wagtailConfig.LOCALES` instead.
102+
103+
### Deprecation of the `{% js_translation_strings %}` template tag
104+
105+
The undocumented `js_translation_strings` template tag will be removed in a future release.
106+
107+
If access to JSON translation strings within JavaScript is needed, use `window.wagtailConfig.STRINGS` instead.

wagtail/admin/templatetags/wagtailadmin_tags.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,10 @@ def admin_theme_classname(context):
684684

685685
@register.simple_tag
686686
def js_translation_strings():
687+
warn(
688+
"The `js_translation_strings` template tag will be removed in a future release.",
689+
category=RemovedInWagtail70Warning,
690+
)
687691
return mark_safe(json.dumps(get_js_translation_strings()))
688692

689693

wagtail/admin/tests/test_templatetags.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from django.utils import timezone
1212
from freezegun import freeze_time
1313

14+
from wagtail.admin.localization import get_js_translation_strings
1415
from wagtail.admin.staticfiles import VERSION_HASH, versioned_static
1516
from wagtail.admin.templatetags.wagtailadmin_tags import (
1617
avatar_url,
@@ -27,6 +28,7 @@
2728
from wagtail.test.utils import WagtailTestUtils
2829
from wagtail.test.utils.template_tests import AdminTemplateTestUtils
2930
from wagtail.users.models import UserProfile
31+
from wagtail.utils.deprecation import RemovedInWagtail70Warning
3032

3133

3234
class TestAvatarTemplateTag(WagtailTestUtils, TestCase):
@@ -378,7 +380,12 @@ def test_i18n_enabled(self):
378380
self.assertTrue(i18n_enabled())
379381

380382
def test_locales(self):
381-
locales_output = locales_tag()
383+
with self.assertWarnsMessage(
384+
RemovedInWagtail70Warning,
385+
"The `locales` template tag will be removed in a future release.",
386+
):
387+
locales_output = locales_tag()
388+
382389
self.assertIsInstance(locales_output, str)
383390
self.assertEqual(
384391
json.loads(locales_output),
@@ -401,6 +408,20 @@ def test_locale_label_from_id(self):
401408
with self.assertNumQueries(0):
402409
self.assertIsNone(locale_label_from_id(self.locale_ids[-1] + 100), None)
403410

411+
def test_js_translation_strings(self):
412+
template = """
413+
{% load wagtailadmin_tags %}
414+
{% js_translation_strings %}
415+
"""
416+
417+
expected = json.dumps(get_js_translation_strings())
418+
419+
with self.assertWarnsMessage(
420+
RemovedInWagtail70Warning,
421+
"The `js_translation_strings` template tag will be removed in a future release.",
422+
):
423+
self.assertHTMLEqual(expected, Template(template).render(Context()))
424+
404425

405426
class ComponentTest(SimpleTestCase):
406427
def test_render_block_component(self):

0 commit comments

Comments
 (0)