discourse/app/assets/javascripts/admin/addon/controllers/admin-site-text-index.js
Roman Rizzi fb9e422bd6
FIX: Show the fallback locale warning when both settings are enabled. (#11787)
We only want to warn admins when both settings are enabled. When "set locale from accept language header" setting is enabled, the user locale will be set based on the header when they register an account on the site, which could be confusing.
2021-01-21 13:09:32 -03:00

89 lines
2.1 KiB
JavaScript

import Controller from "@ember/controller";
import discourseComputed from "discourse-common/utils/decorators";
import discourseDebounce from "discourse-common/lib/debounce";
let lastSearch;
export default Controller.extend({
searching: false,
siteTexts: null,
preferred: false,
queryParams: ["q", "overridden", "locale"],
locale: null,
q: null,
overridden: false,
init() {
this._super(...arguments);
this.set("locale", this.siteSettings.default_locale);
},
_performSearch() {
this.store
.find("site-text", this.getProperties("q", "overridden", "locale"))
.then((results) => {
this.set("siteTexts", results);
})
.finally(() => this.set("searching", false));
},
@discourseComputed()
availableLocales() {
return JSON.parse(this.siteSettings.available_locales);
},
@discourseComputed("locale")
fallbackLocaleFullName() {
if (this.siteTexts.extras.fallback_locale) {
return this.availableLocales.find((l) => {
return l.value === this.siteTexts.extras.fallback_locale;
}).name;
}
},
@discourseComputed("locale")
showFallbackLocaleWarning() {
return (
this.siteSettings.allow_user_locale &&
this.siteSettings.set_locale_from_accept_language_header &&
this.fallbackLocaleFullName
);
},
actions: {
edit(siteText) {
this.transitionToRoute("adminSiteText.edit", siteText.get("id"), {
queryParams: {
locale: this.locale,
localeFullName: this.availableLocales[this.locale],
},
});
},
toggleOverridden() {
this.toggleProperty("overridden");
this.set("searching", true);
discourseDebounce(this, this._performSearch, 400);
},
search() {
const q = this.q;
if (q !== lastSearch) {
this.set("searching", true);
discourseDebounce(this, this._performSearch, 400);
lastSearch = q;
}
},
updateLocale(value) {
this.setProperties({
searching: true,
locale: value,
});
discourseDebounce(this, this._performSearch, 400);
},
},
});