Allow a 'default locale' and locale switcher on status pages

pull/3523/head
Wampie Driessen 1 year ago
parent 8a432ac937
commit 457a3e75dd

@ -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;

@ -403,6 +403,8 @@ class StatusPage extends BeanModel {
autoRefreshInterval: this.autoRefreshInterval, autoRefreshInterval: this.autoRefreshInterval,
published: !!this.published, published: !!this.published,
showTags: !!this.show_tags, showTags: !!this.show_tags,
showLocaleSelector: !!this.show_locale_selector,
defaultLocale: this.default_locale,
domainNameList: this.getDomainNameList(), domainNameList: this.getDomainNameList(),
customCSS: this.custom_css, customCSS: this.custom_css,
footerText: this.footer_text, footerText: this.footer_text,
@ -427,6 +429,8 @@ class StatusPage extends BeanModel {
theme: this.theme, theme: this.theme,
published: !!this.published, published: !!this.published,
showTags: !!this.show_tags, showTags: !!this.show_tags,
showLocaleSelector: !!this.show_locale_selector,
defaultLocale: this.default_locale,
customCSS: this.custom_css, customCSS: this.custom_css,
footerText: this.footer_text, footerText: this.footer_text,
showPoweredBy: !!this.show_powered_by, showPoweredBy: !!this.show_powered_by,

@ -160,6 +160,8 @@ module.exports.statusPageSocketHandler = (socket) => {
//statusPage.published = ; //statusPage.published = ;
//statusPage.search_engine_index = ; //statusPage.search_engine_index = ;
statusPage.show_tags = config.showTags; statusPage.show_tags = config.showTags;
statusPage.show_locale_selector = config.showLocaleSelector;
statusPage.default_locale = config.defaultLocale;
//statusPage.password = null; //statusPage.password = null;
statusPage.footer_text = config.footerText; statusPage.footer_text = config.footerText;
statusPage.custom_css = config.customCSS; statusPage.custom_css = config.customCSS;

@ -291,6 +291,8 @@
"Switch to Light Theme": "Switch to Light Theme", "Switch to Light Theme": "Switch to Light Theme",
"Switch to Dark Theme": "Switch to Dark Theme", "Switch to Dark Theme": "Switch to Dark Theme",
"Show Tags": "Show Tags", "Show Tags": "Show Tags",
"Show Locale Selector": "Show Locale Selector",
"Default Locale": "Default Locale",
"Hide Tags": "Hide Tags", "Hide Tags": "Hide Tags",
"Description": "Description", "Description": "Description",
"No monitors available.": "No monitors available.", "No monitors available.": "No monitors available.",

@ -33,6 +33,13 @@ export default {
this.$i18n.locale = lang; this.$i18n.locale = lang;
localStorage.locale = lang; localStorage.locale = lang;
setPageLocale(); 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();
} }
} }
}; };

@ -56,6 +56,18 @@
<label class="form-check-label" for="showTags">{{ $t("Show Tags") }}</label> <label class="form-check-label" for="showTags">{{ $t("Show Tags") }}</label>
</div> </div>
<div class="my-3 form-check form-switch">
<input id="showLocaleSelector" v-model="config.showLocaleSelector" class="form-check-input" type="checkbox">
<label class="form-check-label" for="showLocaleSelector">{{ $t("Show Locale Selector") }}</label>
</div>
<div class="my-3">
<label for="defaultLocale" class="form-label">{{ $t("Default Locale") }}</label>
<select v-model="config.defaultLocale" class="form-select" id="defaultLocale">
<option v-for="locale in $i18n.availableLocales" :value="locale" :text="$i18n.messages[locale].languageName"></option>
</select>
</div>
<!-- Show Powered By --> <!-- Show Powered By -->
<div class="my-3 form-check form-switch"> <div class="my-3 form-check form-switch">
<input id="show-powered-by" v-model="config.showPoweredBy" class="form-check-input" type="checkbox" data-testid="show-powered-by-checkbox"> <input id="show-powered-by" v-model="config.showPoweredBy" class="form-check-input" type="checkbox" data-testid="show-powered-by-checkbox">
@ -128,7 +140,7 @@
<!-- Main Status Page --> <!-- Main Status Page -->
<div :class="{ edit: enableEditMode}" class="main"> <div :class="{ edit: enableEditMode}" class="main">
<!-- Logo & Title --> <!-- Logo, Title & Language -->
<h1 class="mb-4 title-flex"> <h1 class="mb-4 title-flex">
<!-- Logo --> <!-- Logo -->
<span class="logo-wrapper" @click="showImageCropUploadMethod"> <span class="logo-wrapper" @click="showImageCropUploadMethod">
@ -151,7 +163,14 @@
/> />
<!-- Title --> <!-- Title -->
<Editable v-model="config.title" tag="span" :contenteditable="editMode" :noNL="true" /> <Editable v-model="config.title" class="title" tag="span" :contenteditable="editMode" :noNL="true" />
<!-- Locale Selector -->
<span class="language-selector">
<select v-model="$root.language" class="form-select">
<option v-for="locale in $i18n.availableLocales" :value="locale" :text="$i18n.messages[locale].languageName"></option>
</select>
</span>
</h1> </h1>
<!-- Admin functions --> <!-- Admin functions -->
@ -723,6 +742,10 @@ export default {
}, (this.config.autoRefreshInterval + 10) * 1000); }, (this.config.autoRefreshInterval + 10) * 1000);
this.updateUpdateTimer(); this.updateUpdateTimer();
if (!localStorage.locale && this.config.defaultLocale) {
this.$root.changeCurrentPageLang(this.config.defaultLocale)
}
}).catch( function (error) { }).catch( function (error) {
if (error.response.status === 404) { if (error.response.status === 404) {
location.href = "/page-not-found"; location.href = "/page-not-found";
@ -1143,6 +1166,10 @@ footer {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px; gap: 10px;
.title {
flex-grow: 1;
}
} }
.logo-wrapper { .logo-wrapper {

Loading…
Cancel
Save