Skip to content

Commit ab470a3

Browse files
committed
Merge remote-tracking branch 'upstream/main' into attach-handlers-to-djdebug
2 parents 641e6ce + d04b9d1 commit ab470a3

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ repos:
1616
hooks:
1717
- id: doc8
1818
- repo: https://github.com/asottile/pyupgrade
19-
rev: v3.2.0
19+
rev: v3.2.2
2020
hooks:
2121
- id: pyupgrade
2222
args: [--py37-plus]
2323
- repo: https://github.com/adamchainz/django-upgrade
24-
rev: 1.11.0
24+
rev: 1.12.0
2525
hooks:
2626
- id: django-upgrade
2727
args: [--target-version, "3.2"]
@@ -46,7 +46,7 @@ repos:
4646
args:
4747
- --trailing-comma=es5
4848
- repo: https://github.com/pre-commit/mirrors-eslint
49-
rev: v8.27.0
49+
rev: v8.28.0
5050
hooks:
5151
- id: eslint
5252
files: \.js?$

debug_toolbar/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"SKIP_TEMPLATE_PREFIXES": ("django/forms/widgets/", "admin/widgets/"),
4141
"SQL_WARNING_THRESHOLD": 500, # milliseconds
4242
"OBSERVE_REQUEST_CALLBACK": "debug_toolbar.toolbar.observe_request",
43+
"TOOLBAR_LANGUAGE": None,
4344
}
4445

4546

debug_toolbar/toolbar.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from django.urls import path, resolve
1515
from django.urls.exceptions import Resolver404
1616
from django.utils.module_loading import import_string
17+
from django.utils.translation import get_language, override as lang_override
1718

1819
from debug_toolbar import APP_NAME, settings as dt_settings
1920

@@ -76,7 +77,9 @@ def render_toolbar(self):
7677
self.store()
7778
try:
7879
context = {"toolbar": self}
79-
return render_to_string("debug_toolbar/base.html", context)
80+
lang = self.config["TOOLBAR_LANGUAGE"] or get_language()
81+
with lang_override(lang):
82+
return render_to_string("debug_toolbar/base.html", context)
8083
except TemplateSyntaxError:
8184
if not apps.is_installed("django.contrib.staticfiles"):
8285
raise ImproperlyConfigured(

docs/configuration.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,18 @@ Toolbar options
151151
the request doesn't originate from the toolbar itself, EG that
152152
``is_toolbar_request`` is false for a given request.
153153

154+
* ``TOOLBAR_LANGUAGE``
154155

156+
Default: ``None``
157+
158+
The language used to render the toolbar. If no value is supplied, then the
159+
application's current language will be used. This setting can be used to
160+
render the toolbar in a different language than what the application is
161+
rendered in. For example, if you wish to use English for development,
162+
but want to render your application in French, you would set this to
163+
``"en-us"`` and `settings.LANGUAGE_CODE`_ to ``"fr"``.
164+
165+
.. _settings.LANGUAGE_CODE: https://docs.djangoproject.com/en/stable/ref/settings/#std-setting-LANGUAGE_CODE
155166

156167
Panel options
157168
~~~~~~~~~~~~~

tests/test_integration.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,3 +665,14 @@ def test_displays_server_error(self):
665665
self.selenium.find_element(By.CLASS_NAME, "BuggyPanel").click()
666666
self.wait.until(EC.visibility_of(debug_window))
667667
self.assertEqual(debug_window.text, \n500: Internal Server Error")
668+
669+
def test_toolbar_language_will_render_to_default_language_when_not_set(self):
670+
self.get("/regular/basic/")
671+
hide_button = self.selenium.find_element(By.ID, "djHideToolBarButton")
672+
assert hide_button.text == "Hide »"
673+
674+
@override_settings(DEBUG_TOOLBAR_CONFIG={"TOOLBAR_LANGUAGE": "pt-br"})
675+
def test_toolbar_language_will_render_to_locale_when_set(self):
676+
self.get("/regular/basic/")
677+
hide_button = self.selenium.find_element(By.ID, "djHideToolBarButton")
678+
assert hide_button.text == "Esconder »"

0 commit comments

Comments
 (0)