Skip to content

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

FIX: Do not set locale when replying and also default to none (#33312)

Natalie Tayd81faa122626
diff --git a/app/assets/javascripts/discourse/app/services/composer.js b/app/assets/javascripts/discourse/app/services/composer.js
index 587546deb52..583dec65472 100644
--- a/app/assets/javascripts/discourse/app/services/composer.js
+++ b/app/assets/javascripts/discourse/app/services/composer.js
@@ -1817,25 +1817,12 @@ export default class ComposerService extends Service {
return opts.locale;
}
- if (opts?.post?.locale) {
+ // inherit post locale when editing, not when replying
+ if (opts?.post?.locale && opts.action === Composer.EDIT) {
return opts.post.locale;
}
- if (this.currentUser?.effective_locale) {
- if (
- this.siteSettings.available_content_localization_locales.find(
- (locale) => locale.value === this.currentUser?.effective_locale
- )
- ) {
- return this.currentUser.effective_locale;
- } else {
- // If user's effective locale is not part of available locales,
- // we leave it empty so that a locale value won't be attached to the post.
- return "";
- }
- }
-
- return this.siteSettings.default_locale;
+ return "";
}
}
diff --git a/spec/system/topic_view/localized_content_spec.rb b/spec/system/content_localization_spec.rb
similarity index 68%
rename from spec/system/topic_view/localized_content_spec.rb
rename to spec/system/content_localization_spec.rb
index 0aae80f59fe..2fa95305ba6 100644
--- a/spec/system/topic_view/localized_content_spec.rb
+++ b/spec/system/content_localization_spec.rb
@@ -1,10 +1,12 @@
# frozen_string_literal: true
-RSpec.describe "Localized topic" do
+describe "Content Localization" do
fab!(:japanese_user) { Fabricate(:user, locale: "ja") }
fab!(:site_local_user) { Fabricate(:user, locale: "en") }
fab!(:author) { Fabricate(:user) }
+ fab!(:jap_group) { Fabricate(:group).tap { |g| g.add(japanese_user) } }
+
fab!(:topic) do
Fabricate(:topic, title: "Life strategies from The Art of War", locale: "en", user: author)
end
@@ -28,6 +30,8 @@ RSpec.describe "Localized topic" do
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:topic_list) { PageObjects::Components::TopicList.new }
+ let(:composer) { PageObjects::Components::Composer.new }
+ let(:post_1_obj) { PageObjects::Components::Post.new(1) }
before do
Fabricate(:topic_localization, topic:, locale: "ja", fancy_title: "孫子兵法からの人生戦略")
@@ -38,10 +42,13 @@ RSpec.describe "Localized topic" do
Fabricate(:post_localization, post: post_3, locale: "en", cooked: "A general is one who ..")
end
- context "when the feature is enabled" do
+ context "when the feature is enabled for English and Japanese" do
before do
SiteSetting.allow_user_locale = true
SiteSetting.content_localization_enabled = true
+ SiteSetting.content_localization_allowed_groups =
+ "#{Group::AUTO_GROUPS[:admins]}|#{jap_group.id}"
+ SiteSetting.content_localization_supported_locales = "en|ja"
end
it "shows the correct language based on the selected language and login status" do
@@ -65,5 +72,24 @@ RSpec.describe "Localized topic" do
visit("/")
topic_list.visit_topic_with_title("Life strategies from The Art of War")
end
+
+ it "allows users to set their post's locale when posting" do
+ sign_in(japanese_user)
+
+ visit("/")
+ topic_list.visit_topic_with_title("孫子兵法からの人生戦略")
+
+ topic_page.click_post_action_button(post_1, :reply)
+ expect(composer).to be_opened
+ expect(composer.locale.text.gsub(/\u200B/, "")).to be_blank
+
+ composer.set_locale("日本語")
+ composer.fill_content("新しい投稿の内容 をここに入力します。")
+ composer.create
+
+ sign_in(site_local_user)
+ topic_page.visit_topic(topic)
+ expect(post_1_obj).to have_css(".post-info.post-language")
+ end
end
end
diff --git a/spec/system/page_objects/components/composer.rb b/spec/system/page_objects/components/composer.rb
index 774eaac24ac..db33fd7490f 100644
--- a/spec/system/page_objects/components/composer.rb
+++ b/spec/system/page_objects/components/composer.rb
@@ -8,6 +8,7 @@ module PageObjects
HASHTAG_MENU = ".autocomplete.hashtag-autocomplete"
MENTION_MENU = ".autocomplete.ac-user"
RICH_EDITOR = ".d-editor-input.ProseMirror"
+ POST_LANGUAGE_SELECTOR = ".post-language-selector"
def rich_editor
find(RICH_EDITOR)
@@ -124,6 +125,15 @@ module PageObjects
Components::SelectKit.new(".category-chooser")
end
+ def locale
+ find("#{COMPOSER_ID} #{POST_LANGUAGE_SELECTOR}")
+ end
+
+ def set_locale(locale)
+ Components::DMenu.new(POST_LANGUAGE_SELECTOR).expand
+ find("#{POST_LANGUAGE_SELECTOR} button", text: locale)
+ end
+
def switch_category(category_name)
category_chooser.expand
category_chooser.select_row_by_name(category_name)