diff --git a/js/admin/dist/app.js b/js/admin/dist/app.js index a11382a33..1a4b82bdd 100644 --- a/js/admin/dist/app.js +++ b/js/admin/dist/app.js @@ -18017,10 +18017,10 @@ System.register('flarum/components/Badge', ['flarum/Component', 'flarum/helpers/ });; 'use strict'; -System.register('flarum/components/BasicsPage', ['flarum/components/Page', 'flarum/components/FieldSet', 'flarum/components/Select', 'flarum/components/Button', 'flarum/components/Alert', 'flarum/utils/saveSettings', 'flarum/utils/ItemList'], function (_export, _context) { +System.register('flarum/components/BasicsPage', ['flarum/components/Page', 'flarum/components/FieldSet', 'flarum/components/Select', 'flarum/components/Button', 'flarum/components/Alert', 'flarum/utils/saveSettings', 'flarum/utils/ItemList', 'flarum/components/Switch'], function (_export, _context) { "use strict"; - var Page, FieldSet, Select, Button, Alert, saveSettings, ItemList, BasicsPage; + var Page, FieldSet, Select, Button, Alert, saveSettings, ItemList, Switch, BasicsPage; return { setters: [function (_flarumComponentsPage) { Page = _flarumComponentsPage.default; @@ -18036,6 +18036,8 @@ System.register('flarum/components/BasicsPage', ['flarum/components/Page', 'flar saveSettings = _flarumUtilsSaveSettings.default; }, function (_flarumUtilsItemList) { ItemList = _flarumUtilsItemList.default; + }, function (_flarumComponentsSwitch) { + Switch = _flarumComponentsSwitch.default; }], execute: function () { BasicsPage = function (_Page) { @@ -18055,12 +18057,12 @@ System.register('flarum/components/BasicsPage', ['flarum/components/Page', 'flar this.loading = false; - this.fields = ['forum_title', 'forum_description', 'default_locale', 'default_route', 'welcome_title', 'welcome_message']; + this.fields = ['forum_title', 'forum_description', 'default_locale', 'show_language_selector', 'default_route', 'welcome_title', 'welcome_message']; this.values = {}; var settings = app.data.settings; this.fields.forEach(function (key) { - return _this2.values[key] = m.prop(settings[key]); + return _this2.values[key] = m.prop(settings[key] || false); }); this.localeOptions = {}; @@ -18068,6 +18070,8 @@ System.register('flarum/components/BasicsPage', ['flarum/components/Page', 'flar for (var i in locales) { this.localeOptions[i] = locales[i] + ' (' + i + ')'; } + + if (typeof this.values.show_language_selector() !== "number") this.values.show_language_selector(1); } }, { key: 'view', @@ -18102,6 +18106,12 @@ System.register('flarum/components/BasicsPage', ['flarum/components/Page', 'flar onchange: this.values.default_locale })] }) : '', + Switch.component({ + state: this.values.show_language_selector(), + onchange: this.values.show_language_selector, + children: app.translator.trans('core.admin.basics.show_language_selector_label') + }), + m('br', null), FieldSet.component({ label: app.translator.trans('core.admin.basics.home_page_heading'), className: 'BasicsPage-homePage', diff --git a/js/admin/src/components/BasicsPage.js b/js/admin/src/components/BasicsPage.js index 6ed272a8f..ab0606728 100644 --- a/js/admin/src/components/BasicsPage.js +++ b/js/admin/src/components/BasicsPage.js @@ -5,6 +5,7 @@ import Button from 'flarum/components/Button'; import Alert from 'flarum/components/Alert'; import saveSettings from 'flarum/utils/saveSettings'; import ItemList from 'flarum/utils/ItemList'; +import Switch from 'flarum/components/Switch'; export default class BasicsPage extends Page { init() { @@ -16,6 +17,7 @@ export default class BasicsPage extends Page { 'forum_title', 'forum_description', 'default_locale', + 'show_language_selector', 'default_route', 'welcome_title', 'welcome_message' @@ -23,13 +25,15 @@ export default class BasicsPage extends Page { this.values = {}; const settings = app.data.settings; - this.fields.forEach(key => this.values[key] = m.prop(settings[key])); + this.fields.forEach(key => this.values[key] = m.prop(settings[key] || false)); this.localeOptions = {}; const locales = app.data.locales; for (const i in locales) { this.localeOptions[i] = `${locales[i]} (${i})`; } + + if (typeof this.values.show_language_selector() !== "number") this.values.show_language_selector(1); } view() { @@ -66,6 +70,14 @@ export default class BasicsPage extends Page { }) : ''} + {Switch.component({ + state: this.values.show_language_selector(), + onchange: this.values.show_language_selector, + children: app.translator.trans('core.admin.basics.show_language_selector_label'), + })} + +
+ {FieldSet.component({ label: app.translator.trans('core.admin.basics.home_page_heading'), className: 'BasicsPage-homePage', diff --git a/js/forum/dist/app.js b/js/forum/dist/app.js index 151601392..8543450b1 100644 --- a/js/forum/dist/app.js +++ b/js/forum/dist/app.js @@ -23215,7 +23215,7 @@ System.register('flarum/components/HeaderSecondary', ['flarum/Component', 'flaru items.add('search', app.search.render(), 30); - if (Object.keys(app.data.locales).length > 1) { + if (app.forum.attribute("showLanguageSelector") && Object.keys(app.data.locales).length > 1) { var locales = []; var _loop = function _loop(locale) { diff --git a/js/forum/src/components/HeaderSecondary.js b/js/forum/src/components/HeaderSecondary.js index 912281989..199a86252 100644 --- a/js/forum/src/components/HeaderSecondary.js +++ b/js/forum/src/components/HeaderSecondary.js @@ -39,28 +39,28 @@ export default class HeaderSecondary extends Component { items.add('search', app.search.render(), 30); - if (Object.keys(app.data.locales).length > 1) { + if (app.forum.attribute("showLanguageSelector") && Object.keys(app.data.locales).length > 1) { const locales = []; for (const locale in app.data.locales) { locales.push(Button.component({ - active: app.data.locale === locale, - children: app.data.locales[locale], - icon: app.data.locale === locale ? 'check' : true, - onclick: () => { - if (app.session.user) { - app.session.user.savePreferences({locale}).then(() => window.location.reload()); - } else { - document.cookie = `locale=${locale}; path=/; expires=Tue, 19 Jan 2038 03:14:07 GMT`; - window.location.reload(); + active: app.data.locale === locale, + children: app.data.locales[locale], + icon: app.data.locale === locale ? 'check' : true, + onclick: () => { + if (app.session.user) { + app.session.user.savePreferences({locale}).then(() => window.location.reload()); + } else { + document.cookie = `locale=${locale}; path=/; expires=Tue, 19 Jan 2038 03:14:07 GMT`; + window.location.reload(); + } } - } })); } items.add('locale', SelectDropdown.component({ - children: locales, - buttonClassName: 'Button Button--link' + children: locales, + buttonClassName: 'Button Button--link' }), 20); } diff --git a/src/Api/Serializer/ForumSerializer.php b/src/Api/Serializer/ForumSerializer.php index 80c77224f..ba87f6375 100644 --- a/src/Api/Serializer/ForumSerializer.php +++ b/src/Api/Serializer/ForumSerializer.php @@ -65,6 +65,7 @@ class ForumSerializer extends AbstractSerializer $attributes = [ 'title' => $this->settings->get('forum_title'), 'description' => $this->settings->get('forum_description'), + 'showLanguageSelector' => (bool) $this->settings->get('show_language_selector', true), 'baseUrl' => $url = $this->app->url(), 'basePath' => parse_url($url, PHP_URL_PATH) ?: '', 'debug' => $this->app->inDebugMode(),