mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 07:38:01 +08:00
Add option to hide the language selector (#1106)
* Added option to hide the language selector in the header
* Added `hide_language_selector` Switch to BasicsPage
* Added `hideLanguageSelector` property to ForumSerializer
* Apparently fixed the "Add Extension" button locale.... someone must not have compiled their changes :P
* Changed hideLanguageSelector (and such) to showLanguageSelector
* Change `core.admin.basics.show_language_selector_heading` to be `_label`
* Change showLanguageSelector in ForumSerializer to be boolean, default: true
* Ooops! Remove console.log 🤦♂️
This commit is contained in:
parent
7862bd32dd
commit
60d3d6ef99
18
js/admin/dist/app.js
vendored
18
js/admin/dist/app.js
vendored
|
@ -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',
|
||||
|
|
|
@ -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'),
|
||||
})}
|
||||
|
||||
<br/>
|
||||
|
||||
{FieldSet.component({
|
||||
label: app.translator.trans('core.admin.basics.home_page_heading'),
|
||||
className: 'BasicsPage-homePage',
|
||||
|
|
2
js/forum/dist/app.js
vendored
2
js/forum/dist/app.js
vendored
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue
Block a user