Repository: jazzband/django-debug-toolbar

Issue:
Toolbar language selection
django-debug-toolbar picks up the main apps locale to determine it's language. I'd really like to override this via a setting.

The app I'm working on is in Spanish, but it doesn't really make sense to have the toolbar in spanish; even as a native spanish speaker living in a spanish-speaking country, all the words are weird to me because we use the english words in our day to day work (even when talking between ourselves), and we always use development software in english.

(TBH, I've never seen a developer work with tools configured to use spanish, since all online docs, etc are in english, so all the entire developer subculture has kinda adopted english terms).


Discussion:
I've arrived at this issue looking for a way to change the language of the toolbar as well. 
Is there anyone working on this now?
I see that this is stale for quite some time and willing to help.

Resolving patch:
diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py
--- a/debug_toolbar/settings.py
+++ b/debug_toolbar/settings.py
@@ -40,6 +40,7 @@
     "SKIP_TEMPLATE_PREFIXES": ("django/forms/widgets/", "admin/widgets/"),
     "SQL_WARNING_THRESHOLD": 500,  # milliseconds
     "OBSERVE_REQUEST_CALLBACK": "debug_toolbar.toolbar.observe_request",
+    "TOOLBAR_LANGUAGE": None,
 }
 
 
diff --git a/debug_toolbar/toolbar.py b/debug_toolbar/toolbar.py
--- a/debug_toolbar/toolbar.py
+++ b/debug_toolbar/toolbar.py
@@ -14,6 +14,7 @@
 from django.urls import path, resolve
 from django.urls.exceptions import Resolver404
 from django.utils.module_loading import import_string
+from django.utils.translation import get_language, override as lang_override
 
 from debug_toolbar import APP_NAME, settings as dt_settings
 
@@ -76,7 +77,9 @@ def render_toolbar(self):
             self.store()
         try:
             context = {"toolbar": self}
-            return render_to_string("debug_toolbar/base.html", context)
+            lang = self.config["TOOLBAR_LANGUAGE"] or get_language()
+            with lang_override(lang):
+                return render_to_string("debug_toolbar/base.html", context)
         except TemplateSyntaxError:
             if not apps.is_installed("django.contrib.staticfiles"):
                 raise ImproperlyConfigured(


Test patch:
diff --git a/tests/test_integration.py b/tests/test_integration.py
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -665,3 +665,14 @@ def test_displays_server_error(self):
         self.selenium.find_element(By.CLASS_NAME, "BuggyPanel").click()
         self.wait.until(EC.visibility_of(debug_window))
         self.assertEqual(debug_window.text, "»\n500: Internal Server Error")
+
+    def test_toolbar_language_will_render_to_default_language_when_not_set(self):
+        self.get("/regular/basic/")
+        hide_button = self.selenium.find_element(By.ID, "djHideToolBarButton")
+        assert hide_button.text == "Hide »"
+
+    @override_settings(DEBUG_TOOLBAR_CONFIG={"TOOLBAR_LANGUAGE": "pt-br"})
+    def test_toolbar_language_will_render_to_locale_when_set(self):
+        self.get("/regular/basic/")
+        hide_button = self.selenium.find_element(By.ID, "djHideToolBarButton")
+        assert hide_button.text == "Esconder »"