-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
feat(status-page): add per-status-page language setting for anonymous visitors #6615
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
base: master
Are you sure you want to change the base?
Changes from all commits
60ade05
67659e7
6389a95
682cf7c
934874a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| exports.up = async function (knex) { | ||
| await knex.schema.alterTable("status_page", function (table) { | ||
| table.string("language", 20); | ||
| }); | ||
| }; | ||
|
|
||
| exports.down = function (knex) { | ||
| return knex.schema.alterTable("status_page", function (table) { | ||
| table.dropColumn("language"); | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -390,6 +390,9 @@ | |||||
| "Footer Text": "Footer Text", | ||||||
| "RSS Title": "RSS Title", | ||||||
| "Leave blank to use status page title": "Leave blank to use status page title", | ||||||
| "Status Page Language": "Status Page Language", | ||||||
| "Use browser language": "Use browser language", | ||||||
| "statusPageLanguageDescription": "Set the display language for anonymous visitors to this status page", | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can be more explicit here what this does
Suggested change
|
||||||
| "Refresh Interval": "Refresh Interval", | ||||||
| "Refresh Interval Description": "The status page will do a full site refresh every {0} seconds", | ||||||
| "Show Powered By": "Show Powered By", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ export default { | |||||||
| data() { | ||||||||
| return { | ||||||||
| language: currentLocale(), | ||||||||
| persistLanguage: true, | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is only ever written, what are you trying to do here? |
||||||||
| }; | ||||||||
| }, | ||||||||
|
|
||||||||
|
|
@@ -17,22 +18,40 @@ export default { | |||||||
|
|
||||||||
| watch: { | ||||||||
| async language(lang) { | ||||||||
| await this.changeLang(lang); | ||||||||
| await this.changeLang(lang, { | ||||||||
| persist: this.persistLanguage, | ||||||||
| }); | ||||||||
| this.persistLanguage = true; | ||||||||
| }, | ||||||||
| }, | ||||||||
|
|
||||||||
| methods: { | ||||||||
| /** | ||||||||
| * Set the application language | ||||||||
| * @param {string} lang Language code to switch to | ||||||||
| * @param {{ persist?: boolean }} options Options for language change | ||||||||
| * @returns {void} | ||||||||
| */ | ||||||||
| setLanguage(lang, options = {}) { | ||||||||
| this.persistLanguage = options.persist !== false; | ||||||||
| this.language = lang; | ||||||||
| }, | ||||||||
|
|
||||||||
| /** | ||||||||
| * Change the application language | ||||||||
| * @param {string} lang Language code to switch to | ||||||||
| * @param {{ persist?: boolean }} options Options for language change | ||||||||
| * @returns {Promise<void>} | ||||||||
| */ | ||||||||
| async changeLang(lang) { | ||||||||
| async changeLang(lang, options = {}) { | ||||||||
| const persist = options.persist !== false; | ||||||||
|
Comment on lines
+46
to
+47
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't use single-item options as it is harder to reason about them when only used once
Suggested change
|
||||||||
| let message = (await langModules["../lang/" + lang + ".json"]()).default; | ||||||||
| this.$i18n.setLocaleMessage(lang, message); | ||||||||
| this.$i18n.locale = lang; | ||||||||
| localStorage.locale = lang; | ||||||||
| setPageLocale(); | ||||||||
| if (persist) { | ||||||||
| localStorage.locale = lang; | ||||||||
| } | ||||||||
| setPageLocale(lang); | ||||||||
| timeDurationFormatter.updateLocale(lang); | ||||||||
| }, | ||||||||
| }, | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -205,6 +205,25 @@ | |
| </div> | ||
| </div> | ||
|
|
||
| <!-- Status Page Language --> | ||
| <div class="my-3"> | ||
| <label for="status-page-language" class="form-label">{{ $t("Status Page Language") }}</label> | ||
| <select | ||
| id="status-page-language" | ||
| v-model="config.language" | ||
| class="form-select" | ||
| data-testid="language-select" | ||
| > | ||
| <option :value="null">{{ $t("Use browser language") }}</option> | ||
| <option v-for="lang in $i18n.availableLocales" :key="lang" :value="lang"> | ||
| {{ $i18n.messages[lang].languageName }} | ||
| </option> | ||
| </select> | ||
| <div class="form-text"> | ||
| {{ $t("statusPageLanguageDescription") }} | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- Custom CSS --> | ||
| <div class="my-3"> | ||
| <div class="mb-1">{{ $t("Custom CSS") }}</div> | ||
|
|
@@ -857,6 +876,10 @@ export default { | |
| if (res.ok) { | ||
| this.config = res.config; | ||
|
|
||
| if (!("language" in this.config)) { | ||
| this.config.language = null; | ||
| } | ||
|
|
||
|
Comment on lines
+879
to
+882
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this happening? |
||
| if (!this.config.customCSS) { | ||
| this.config.customCSS = "body {\n" + " \n" + "}\n"; | ||
| } | ||
|
|
@@ -942,6 +965,27 @@ export default { | |
| this.config.domainNameList = []; | ||
| } | ||
|
|
||
| if (!("language" in this.config)) { | ||
| this.config.language = null; | ||
| } | ||
|
|
||
| if (this.config.icon) { | ||
| this.imgDataUrl = this.config.icon; | ||
| } | ||
|
|
||
| // Apply configured language if the visitor hasn't set their own preference | ||
| if (this.config.language && !localStorage.locale) { | ||
| this.$root.setLanguage(this.config.language, { persist: false }); | ||
| } | ||
|
|
||
| this.incident = res.data.incident; | ||
| this.maintenanceList = res.data.maintenanceList; | ||
| this.$root.publicGroupList = res.data.publicGroupList; | ||
|
|
||
| if (!this.config.domainNameList) { | ||
| this.config.domainNameList = []; | ||
| } | ||
|
|
||
|
Comment on lines
+968
to
+988
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please explain what you added here and why. |
||
| if (this.config.icon) { | ||
| this.imgDataUrl = this.config.icon; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -62,12 +62,13 @@ export function timezoneList() { | |||||
|
|
||||||
| /** | ||||||
| * Set the locale of the HTML page | ||||||
| * @param {string} locale The locale to use | ||||||
| * @returns {void} | ||||||
| */ | ||||||
| export function setPageLocale() { | ||||||
| export function setPageLocale(locale = currentLocale()) { | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is resonably hard to read. Please change it like this instead and adjust the callsites. This feedback also is applicable to
Suggested change
|
||||||
| const html = document.documentElement; | ||||||
| html.setAttribute("lang", currentLocale()); | ||||||
| html.setAttribute("dir", localeDirection()); | ||||||
| html.setAttribute("lang", locale); | ||||||
| html.setAttribute("dir", localeDirection(locale)); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the equivalent, or?