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 00000000..1f7a1393 --- /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 23558298..fdf2acca 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -240,6 +240,8 @@ class StatusPage extends BeanModel { theme: this.theme, 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, @@ -263,6 +265,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 ee1c68d3..1276ec44 100644 --- a/server/socket-handlers/status-page-socket-handler.js +++ b/server/socket-handlers/status-page-socket-handler.js @@ -159,6 +159,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 21b0eec7..173f8a6d 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -283,6 +283,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 9061e7d3..32d23e9f 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 af2f028d..9756cde7 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -48,6 +48,18 @@ +
+ + +
+ +
+ + +
+
@@ -120,7 +132,7 @@
- +

@@ -143,7 +155,14 @@ /> - + + + + + +

@@ -707,6 +726,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; }).catch( function (error) { if (error.response.status === 404) { @@ -1134,6 +1157,10 @@ footer { display: flex; align-items: center; gap: 10px; + + .title { + flex-grow: 1; + } } .logo-wrapper {