File tree 4 files changed +27
-1
lines changed
4 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 40
40
"SKIP_TEMPLATE_PREFIXES" : ("django/forms/widgets/" , "admin/widgets/" ),
41
41
"SQL_WARNING_THRESHOLD" : 500 , # milliseconds
42
42
"OBSERVE_REQUEST_CALLBACK" : "debug_toolbar.toolbar.observe_request" ,
43
+ "TOOLBAR_LANGUAGE" : None ,
43
44
}
44
45
45
46
Original file line number Diff line number Diff line change 14
14
from django .urls import path , resolve
15
15
from django .urls .exceptions import Resolver404
16
16
from django .utils .module_loading import import_string
17
+ from django .utils .translation import get_language , override as lang_override
17
18
18
19
from debug_toolbar import APP_NAME , settings as dt_settings
19
20
@@ -76,7 +77,9 @@ def render_toolbar(self):
76
77
self .store ()
77
78
try :
78
79
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 )
80
83
except TemplateSyntaxError :
81
84
if not apps .is_installed ("django.contrib.staticfiles" ):
82
85
raise ImproperlyConfigured (
Original file line number Diff line number Diff line change @@ -149,7 +149,18 @@ Toolbar options
149
149
the request doesn't originate from the toolbar itself, EG that
150
150
``is_toolbar_request `` is false for a given request.
151
151
152
+ * ``TOOLBAR_LANGUAGE ``
152
153
154
+ Default: ``None ``
155
+
156
+ The language used to render the toolbar. If no value is supplied, then the
157
+ application's current language will be used. This setting can be used to
158
+ render the toolbar in a different language than what the application is
159
+ rendered in. For example, if you wish to use English for development,
160
+ but want to render your application in French, you would set this to
161
+ ``"en-us" `` and `settings.LANGUAGE_CODE `_ to ``"fr" ``.
162
+
163
+ .. _settings.LANGUAGE_CODE : https://docs.djangoproject.com/en/stable/ref/settings/#std-setting-LANGUAGE_CODE
153
164
154
165
Panel options
155
166
~~~~~~~~~~~~~
Original file line number Diff line number Diff line change @@ -665,3 +665,14 @@ def test_displays_server_error(self):
665
665
self .selenium .find_element (By .CLASS_NAME , "BuggyPanel" ).click ()
666
666
self .wait .until (EC .visibility_of (debug_window ))
667
667
self .assertEqual (debug_window .text , "»\n 500: 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 »"
You can’t perform that action at this time.
0 commit comments