Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions db/patch-status-page-locale-selector.sql
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions server/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Database {
"patch-monitor-oauth-cc.sql": true,
"patch-add-timeout-monitor.sql": true,
"patch-add-gamedig-given-port.sql": true,
"patch-status-page-locale-selector.sql": true,
louislam marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down
4 changes: 4 additions & 0 deletions server/model/status_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,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,
Expand All @@ -254,6 +256,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,
Expand Down
2 changes: 2 additions & 0 deletions server/socket-handlers/status-page-socket-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,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;
Expand Down
2 changes: 2 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,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.",
Expand Down
10 changes: 10 additions & 0 deletions src/mixins/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ 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.
*/
async changeCurrentPageLang(lang) {
let message = (await langModules["../lang/" + lang + ".json"]()).default;
this.$i18n.setLocaleMessage(lang, message);
this.$i18n.locale = lang;
setPageLocale();
}
}
};
31 changes: 29 additions & 2 deletions src/pages/StatusPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
<label class="form-check-label" for="showTags">{{ $t("Show Tags") }}</label>
</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 id="defaultLocale" v-model="config.defaultLocale" class="form-select">
<option v-for="locale in $i18n.availableLocales" :key="locale" :value="locale" :text="$i18n.messages[locale].languageName"></option>
</select>
</div>

<!-- Show Powered By -->
<div class="my-3 form-check form-switch">
<input id="show-powered-by" v-model="config.showPoweredBy" class="form-check-input" type="checkbox">
Expand Down Expand Up @@ -116,7 +128,7 @@

<!-- Main Status Page -->
<div :class="{ edit: enableEditMode}" class="main">
<!-- Logo & Title -->
<!-- Logo, Title & Language -->
<h1 class="mb-4 title-flex">
<!-- Logo -->
<span class="logo-wrapper" @click="showImageCropUploadMethod">
Expand All @@ -139,7 +151,14 @@
/>

<!-- 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" :key="locale" :value="locale" :text="$i18n.messages[locale].languageName"></option>
</select>
</span>
</h1>

<!-- Admin functions -->
Expand Down Expand Up @@ -697,6 +716,10 @@ export default {
this.incident = res.data.incident;
this.maintenanceList = res.data.maintenanceList;
this.$root.publicGroupList = res.data.publicGroupList;

if (!localStorage.locale && this.config.defaultLocale) {
this.$root.changeCurrentPageLang(this.config.defaultLocale);
}
}).catch( function (error) {
if (error.response.status === 404) {
location.href = "/page-not-found";
Expand Down Expand Up @@ -1075,6 +1098,10 @@ footer {
display: flex;
align-items: center;
gap: 10px;

.title {
flex-grow: 1;
}
}

.logo-wrapper {
Expand Down