From 0d13c3b439b9ae9fa8b3226d302871681c4a1541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 18 Nov 2016 07:54:17 +0100 Subject: [PATCH] Add OctoPrint.options.locale and if set send X-Locale header on requests See #1593 --- docs/jsclientlib/base.rst | 4 ++++ src/octoprint/static/js/app/client/base.js | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/jsclientlib/base.rst b/docs/jsclientlib/base.rst index e59cca69..65a56340 100644 --- a/docs/jsclientlib/base.rst +++ b/docs/jsclientlib/base.rst @@ -14,6 +14,10 @@ ``OctoPrint.options.baseurl`` The base URL of the OctoPrint API + ``OctoPrint.options.locale`` + The locale to set in ``X-Locale`` headers on API requests. Useful for API + endpoints that might return localized content. + .. js:data:: OctoPrint.plugins Registration of client library components provided by plugins. diff --git a/src/octoprint/static/js/app/client/base.js b/src/octoprint/static/js/app/client/base.js index eb159d0a..c0ea5292 100644 --- a/src/octoprint/static/js/app/client/base.js +++ b/src/octoprint/static/js/app/client/base.js @@ -46,7 +46,8 @@ OctoPrint.options = { "baseurl": undefined, - "apikey": undefined + "apikey": undefined, + "locale": undefined }; OctoPrint.plugins = {}; @@ -65,6 +66,10 @@ var headers = $.extend({}, additional); headers["X-Api-Key"] = OctoPrint.options.apikey; + if (OctoPrint.options.locale !== undefined) { + headers["X-Locale"] = OctoPrint.options.locale; + } + return headers; };