From 457a3e75ddd02bfa4f6657f40193ffc26f34da01 Mon Sep 17 00:00:00 2001 From: Wampie Driessen <1059058+wampiedriessen@users.noreply.github.com> Date: Thu, 3 Aug 2023 16:32:52 +0200 Subject: [PATCH 1/9] Allow a 'default locale' and locale switcher on status pages --- db/patch-status-page-locale-selector.sql | 5 +++ server/model/status_page.js | 4 +++ .../status-page-socket-handler.js | 2 ++ src/lang/en.json | 2 ++ src/mixins/lang.js | 7 +++++ src/pages/StatusPage.vue | 31 +++++++++++++++++-- 6 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 db/patch-status-page-locale-selector.sql diff --git a/db/patch-status-page-locale-selector.sql b/db/patch-status-page-locale-selector.sql new file mode 100644 index 000000000..3335e3ba0 --- /dev/null +++ b/db/patch-status-page-locale-selector.sql @@ -0,0 +1,5 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; +ALTER TABLE status_page ADD show_locale_selector BOOLEAN NOT NULL DEFAULT 0; +ALTER TABLE status_page ADD default_locale TEXT DEFAULT ""; +COMMIT; diff --git a/server/model/status_page.js b/server/model/status_page.js index 38f548ebb..6cf2ef717 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -403,6 +403,8 @@ class StatusPage extends BeanModel { autoRefreshInterval: this.autoRefreshInterval, published: !!this.published, showTags: !!this.show_tags, + showLocaleSelector: !!this.show_locale_selector, + defaultLocale: this.default_locale, domainNameList: this.getDomainNameList(), customCSS: this.custom_css, footerText: this.footer_text, @@ -427,6 +429,8 @@ class StatusPage extends BeanModel { theme: this.theme, published: !!this.published, showTags: !!this.show_tags, + showLocaleSelector: !!this.show_locale_selector, + defaultLocale: this.default_locale, customCSS: this.custom_css, footerText: this.footer_text, showPoweredBy: !!this.show_powered_by, diff --git a/server/socket-handlers/status-page-socket-handler.js b/server/socket-handlers/status-page-socket-handler.js index cbcc52b8f..3f7604c3e 100644 --- a/server/socket-handlers/status-page-socket-handler.js +++ b/server/socket-handlers/status-page-socket-handler.js @@ -160,6 +160,8 @@ module.exports.statusPageSocketHandler = (socket) => { //statusPage.published = ; //statusPage.search_engine_index = ; statusPage.show_tags = config.showTags; + statusPage.show_locale_selector = config.showLocaleSelector; + statusPage.default_locale = config.defaultLocale; //statusPage.password = null; statusPage.footer_text = config.footerText; statusPage.custom_css = config.customCSS; diff --git a/src/lang/en.json b/src/lang/en.json index e215f1031..48498df9d 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -291,6 +291,8 @@ "Switch to Light Theme": "Switch to Light Theme", "Switch to Dark Theme": "Switch to Dark Theme", "Show Tags": "Show Tags", + "Show Locale Selector": "Show Locale Selector", + "Default Locale": "Default Locale", "Hide Tags": "Hide Tags", "Description": "Description", "No monitors available.": "No monitors available.", diff --git a/src/mixins/lang.js b/src/mixins/lang.js index 9061e7d3d..76b5b755a 100644 --- a/src/mixins/lang.js +++ b/src/mixins/lang.js @@ -33,6 +33,13 @@ export default { this.$i18n.locale = lang; localStorage.locale = lang; setPageLocale(); + }, + /** Change the language for the current page (no localstore set) */ + async changeCurrentPageLang(lang) { + let message = (await langModules["../lang/" + lang + ".json"]()).default; + this.$i18n.setLocaleMessage(lang, message); + this.$i18n.locale = lang; + setPageLocale(); } } }; diff --git a/src/pages/StatusPage.vue b/src/pages/StatusPage.vue index 116968282..96823b970 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -56,6 +56,18 @@ +