diff --git a/db/knex_migrations/2023-09-13-1047-locale-on-statuspage.js b/db/knex_migrations/2023-09-13-1047-locale-on-statuspage.js new file mode 100644 index 000000000..1f7a13937 --- /dev/null +++ b/db/knex_migrations/2023-09-13-1047-locale-on-statuspage.js @@ -0,0 +1,15 @@ +exports.up = function (knex) { + return knex.schema + .alterTable("status_page", function (table) { + table.boolean("show_locale_selector").notNullable().defaultTo(false); + table.string("default_locale").nullable().defaultTo(""); + }); +}; + +exports.down = function (knex) { + return knex.schema + .alterTable("status_page", function (table) { + table.dropColumn("default_locale"); + table.dropColumn("show_locale_selector"); + }); +}; 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 0804da15d..af9e1bfb7 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 07d3a3d24..eab8b75a4 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -301,6 +301,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..32d23e9f5 100644 --- a/src/mixins/lang.js +++ b/src/mixins/lang.js @@ -33,6 +33,17 @@ export default { this.$i18n.locale = lang; localStorage.locale = lang; setPageLocale(); + }, + /** + * Change the language for the current page (no localstore set) + * @param {string} lang Code of language to switch to. + * @returns {Promise} + */ + 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..a7be0591e 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -56,6 +56,18 @@ +
+ + +
+ +
+ + +
+
@@ -128,7 +140,7 @@
- +

@@ -151,7 +163,14 @@ /> - + + + + + +

@@ -715,6 +734,10 @@ export default { this.maintenanceList = res.data.maintenanceList; this.$root.publicGroupList = res.data.publicGroupList; + if (!localStorage.locale && this.config.defaultLocale) { + this.$root.changeCurrentPageLang(this.config.defaultLocale); + } + this.loading = false; // Configure auto-refresh loop @@ -1143,6 +1166,10 @@ footer { display: flex; align-items: center; gap: 10px; + + .title { + flex-grow: 1; + } } .logo-wrapper {