File tree Expand file tree Collapse file tree 4 files changed +27
-1
lines changed Expand file tree Collapse file tree 4 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1414from django .urls import path , resolve
1515from django .urls .exceptions import Resolver404
1616from django .utils .module_loading import import_string
17+ from django .utils .translation import get_language , override as lang_override
1718
1819from 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 (
Original file line number Diff line number Diff line change @@ -149,7 +149,18 @@ Toolbar options
149149 the request doesn't originate from the toolbar itself, EG that
150150 ``is_toolbar_request `` is false for a given request.
151151
152+ * ``TOOLBAR_LANGUAGE ``
152153
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
153164
154165Panel options
155166~~~~~~~~~~~~~
Original file line number Diff line number Diff 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 , "»\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