This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/services/logs-notice.js.es6
Osama Sayegh f3c07e27d9
FIX: correct translations for logs error rate notice (#7622)
The problem here is that hour and minute were passed to the %{duration} variable which made them impossible to translate in other languages.

I wonder if it's worth having 2 almost identical translations just for "reached" and "exceeded"? Perhaps we could combine them in one copy?
2019-05-28 22:10:51 +03:00

83 lines
2.0 KiB
JavaScript

import {
default as computed,
on,
observes
} from "ember-addons/ember-computed-decorators";
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
const LOGS_NOTICE_KEY = "logs-notice-text";
const LogsNotice = Ember.Object.extend({
text: "",
@on("init")
_setup() {
if (!this.isActivated) return;
const text = this.keyValueStore.getItem(LOGS_NOTICE_KEY);
if (text) this.set("text", text);
this.messageBus.subscribe("/logs_error_rate_exceeded", data => {
const duration = data.duration;
const rate = data.rate;
let siteSettingLimit = 0;
if (duration === "minute") {
siteSettingLimit = this.siteSettings.alert_admins_if_errors_per_minute;
} else if (duration === "hour") {
siteSettingLimit = this.siteSettings.alert_admins_if_errors_per_hour;
}
let translationKey = rate === siteSettingLimit ? "reached" : "exceeded";
translationKey += `_${duration}_MF`;
this.set(
"text",
I18n.messageFormat(`logs_error_rate_notice.${translationKey}`, {
relativeAge: autoUpdatingRelativeAge(
new Date(data.publish_at * 1000)
),
rate,
limit: siteSettingLimit,
url: Discourse.getURL("/logs")
})
);
});
},
@computed("text")
isEmpty(text) {
return Ember.isEmpty(text);
},
@computed("text")
message(text) {
return new Handlebars.SafeString(text);
},
@computed("currentUser")
isAdmin(currentUser) {
return currentUser && currentUser.admin;
},
@computed("isEmpty", "isAdmin")
hidden(isEmpty, isAdmin) {
return !isAdmin || isEmpty;
},
@observes("text")
_updateKeyValueStore() {
this.keyValueStore.setItem(LOGS_NOTICE_KEY, this.text);
},
@computed(
"siteSettings.alert_admins_if_errors_per_hour",
"siteSettings.alert_admins_if_errors_per_minute"
)
isActivated(errorsPerHour, errorsPerMinute) {
return errorsPerHour > 0 || errorsPerMinute > 0;
}
});
export default LogsNotice;