File tree Expand file tree Collapse file tree 5 files changed +30
-4
lines changed Expand file tree Collapse file tree 5 files changed +30
-4
lines changed Original file line number Diff line number Diff 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"]
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?$
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 @@ -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
156167Panel options
157168~~~~~~~~~~~~~
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