Skip to content

A platform for community discussion. Free, open, simple.

FIX: Also show the 'post language indicator' when the post gets updated to translated content (#36806)

Natalie Taya6462a110c90
diff --git a/frontend/discourse/app/models/post.js b/frontend/discourse/app/models/post.js
index 71545da5515..1da0679b3c7 100644
--- a/frontend/discourse/app/models/post.js
+++ b/frontend/discourse/app/models/post.js
@@ -216,6 +216,9 @@ export default class Post extends RestModel {
@trackedPostProperty yours;
@trackedPostProperty user_custom_fields;
@trackedPostProperty post_localizations;
+ @trackedPostProperty is_localized;
+ @trackedPostProperty language;
+ @trackedPostProperty localization_outdated;
@alias("can_edit") canEdit; // for compatibility with existing code
@equal("trust_level", 0) new_user;
diff --git a/frontend/discourse/tests/integration/components/post/post-test.gjs b/frontend/discourse/tests/integration/components/post/post-test.gjs
index 65827cc1b9b..0109f9c920b 100644
--- a/frontend/discourse/tests/integration/components/post/post-test.gjs
+++ b/frontend/discourse/tests/integration/components/post/post-test.gjs
@@ -1,5 +1,5 @@
import { getOwner } from "@ember/owner";
-import { click, render, triggerEvent } from "@ember/test-helpers";
+import { click, render, settled, triggerEvent } from "@ember/test-helpers";
import { module, test } from "qunit";
import Post from "discourse/components/post";
import DMenus from "discourse/float-kit/components/d-menus";
@@ -339,6 +339,24 @@ module("Integration | Component | Post", function (hooks) {
assert.dom(".read-state").exists();
});
+ test("language indicator appears after localization properties are updated", async function (assert) {
+ this.siteSettings.available_locales = [{ value: "ja", name: "Japanese" }];
+
+ await renderComponent(this.post);
+
+ assert
+ .dom(".post-language")
+ .doesNotExist("language indicator not shown initially");
+
+ this.post.is_localized = true;
+ this.post.language = "ja";
+ await settled();
+
+ assert
+ .dom(".post-language")
+ .exists("language indicator appears after update");
+ });
+
test("reply directly above (suppressed)", async function (assert) {
this.post.reply_to_user = {
username: "eviltrout",
diff --git a/frontend/discourse/tests/unit/models/post-test.js b/frontend/discourse/tests/unit/models/post-test.js
index 0d3a44c3dd4..aedf57db57e 100644
--- a/frontend/discourse/tests/unit/models/post-test.js
+++ b/frontend/discourse/tests/unit/models/post-test.js
@@ -145,4 +145,25 @@ module("Unit | Model | post", function (hooks) {
assert.strictEqual(post.likeAction, null, "likeAction was reset to null");
});
+
+ test("updateFromPost updates localization properties", function (assert) {
+ const post = this.store.createRecord("post", {
+ id: 1,
+ is_localized: false,
+ language: null,
+ localization_outdated: false,
+ });
+
+ post.updateFromPost(
+ this.store.createRecord("post", {
+ is_localized: true,
+ language: "ja",
+ localization_outdated: true,
+ })
+ );
+
+ assert.true(post.is_localized);
+ assert.strictEqual(post.language, "ja");
+ assert.true(post.localization_outdated);
+ });
});