Skip to content

Commit be7675b

Browse files
committed
DEV: Replace api.modifyClass(model...) with addTrackedPostProperty
This commit replace patching the model class with a call to the new api `addTrackedPostProperty` to add tracked properties to the model
1 parent aa29447 commit be7675b

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

assets/javascripts/discourse/initializers/extend-for-translate-button.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { tracked } from "@glimmer/tracking";
21
import { ajax } from "discourse/lib/ajax";
32
import { popupAjaxError } from "discourse/lib/ajax-error";
43
import { withPluginApi } from "discourse/lib/plugin-api";
54
import { withSilencedDeprecations } from "discourse-common/lib/deprecated";
6-
import I18n from "I18n";
5+
import { i18n } from "discourse-i18n";
76
import ToggleTranslationButton from "../components/post-menu/toggle-translation-button";
87
import TranslatedPost from "../components/translated-post";
98

@@ -27,19 +26,13 @@ function customizePostMenu(api, container) {
2726
);
2827

2928
if (transformerRegistered) {
30-
// the plugin outlet is not updated when the post instance is modified unless we extend it to add the tracking to
31-
// the new properties
32-
api.modifyClass(
33-
"model:post",
34-
(Superclass) =>
35-
class extends Superclass {
36-
@tracked detectedLang;
37-
@tracked isTranslating;
38-
@tracked isTranslated;
39-
@tracked translatedText;
40-
@tracked translatedTitle;
41-
}
42-
);
29+
// the plugin outlet is not updated when the post instance is modified unless we register the new properties as
30+
// tracked
31+
api.addTrackedPostProperty("detectedLang");
32+
api.addTrackedPostProperty("isTranslating");
33+
api.addTrackedPostProperty("isTranslated");
34+
api.addTrackedPostProperty("translatedText");
35+
api.addTrackedPostProperty("translatedTitle");
4336

4437
api.renderBeforeWrapperOutlet("post-menu", TranslatedPost);
4538
}
@@ -86,7 +79,7 @@ function customizeWidgetPostMenu(api) {
8679
...titleElements,
8780
dec.h(
8881
"div.post-attribution",
89-
I18n.t("translator.translated_from", { language, translator })
82+
i18n("translator.translated_from", { language, translator })
9083
),
9184
dec.cooked(dec.attrs.translated_text),
9285
]);

0 commit comments

Comments
 (0)