Skip to content

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

Revert "FEATURE: Add post language on creating a new post (#33001)" (#33157)

Keegan Georged5b72a54ae5b
diff --git a/app/assets/javascripts/discourse/app/components/composer-action-title.gjs b/app/assets/javascripts/discourse/app/components/composer-action-title.gjs
index a7c528bbcff..00b4dfb8d64 100644
--- a/app/assets/javascripts/discourse/app/components/composer-action-title.gjs
+++ b/app/assets/javascripts/discourse/app/components/composer-action-title.gjs
@@ -1,10 +1,8 @@
import Component from "@ember/component";
import { hash } from "@ember/helper";
import { alias } from "@ember/object/computed";
-import { service } from "@ember/service";
import { htmlSafe } from "@ember/template";
import { classNames } from "@ember-decorators/component";
-import PostLanguageSelector from "discourse/components/post-language-selector";
import discourseComputed from "discourse/lib/decorators";
import escape from "discourse/lib/escape";
import { iconHTML } from "discourse/lib/icon-library";
@@ -30,9 +28,6 @@ const TITLES = {
@classNames("composer-action-title")
export default class ComposerActionTitle extends Component {
- @service currentUser;
- @service siteSettings;
-
@alias("model.replyOptions") options;
@alias("model.action") action;
@@ -69,20 +64,6 @@ export default class ComposerActionTitle extends Component {
}
}
- get showPostLanguageSelector() {
- const allowedActions = [CREATE_TOPIC, EDIT, REPLY];
- if (
- this.currentUser &&
- this.siteSettings.experimental_content_localization &&
- this.currentUser.can_localize_content &&
- allowedActions.includes(this.model.action)
- ) {
- return true;
- }
-
- return false;
- }
-
_formatEditUserPost(userAvatar, userLink, postLink, originalUser) {
let editTitle = `
<a class="post-link" href="${postLink.href}">${postLink.anchor}</a>
@@ -133,12 +114,5 @@ export default class ComposerActionTitle extends Component {
<span class="action-title" role="heading" aria-level="1">
{{this.actionTitle}}
</span>
-
- {{#if this.showPostLanguageSelector}}
- <PostLanguageSelector
- @composerModel={{this.model}}
- @selectedLanguage={{this.model.locale}}
- />
- {{/if}}
</template>
}
diff --git a/app/assets/javascripts/discourse/app/components/edit-category-localizations.gjs b/app/assets/javascripts/discourse/app/components/edit-category-localizations.gjs
index f01f5b7f2cd..f9569973bf6 100644
--- a/app/assets/javascripts/discourse/app/components/edit-category-localizations.gjs
+++ b/app/assets/javascripts/discourse/app/components/edit-category-localizations.gjs
@@ -10,7 +10,7 @@ export default class EditCategoryLocalizations extends buildCategoryPanel(
@service siteSettings;
get availableLocales() {
- return this.siteSettings.available_content_localization_locales;
+ return JSON.parse(this.siteSettings.available_locales);
}
<template>
diff --git a/app/assets/javascripts/discourse/app/components/language-switcher.gjs b/app/assets/javascripts/discourse/app/components/language-switcher.gjs
index e0300fc391d..82934592186 100644
--- a/app/assets/javascripts/discourse/app/components/language-switcher.gjs
+++ b/app/assets/javascripts/discourse/app/components/language-switcher.gjs
@@ -12,6 +12,21 @@ export default class LanguageSwitcher extends Component {
@service siteSettings;
@service router;
+ get localeOptions() {
+ const targetLanguages = (
+ this.siteSettings.experimental_content_localization_supported_locales ||
+ ""
+ ).split("|");
+ return JSON.parse(this.siteSettings.available_locales)
+ .filter(({ value }) => targetLanguages.includes(value))
+ .map(({ name, value }) => {
+ return {
+ label: name,
+ value,
+ };
+ });
+ }
+
@action
async changeLocale(locale) {
cookie("locale", locale, { path: "/" });
@@ -36,16 +51,13 @@ export default class LanguageSwitcher extends Component {
>
<:content>
<DropdownMenu as |dropdown|>
- {{#each
- this.siteSettings.available_content_localization_locales
- as |option|
- }}
+ {{#each this.localeOptions as |option|}}
<dropdown.item
class="locale-options"
data-menu-option-id={{option.value}}
>
<DButton
- @translatedLabel={{option.name}}
+ @translatedLabel={{option.label}}
@action={{fn this.changeLocale option.value}}
/>
</dropdown.item>
diff --git a/app/assets/javascripts/discourse/app/components/modal/post-translations.gjs b/app/assets/javascripts/discourse/app/components/modal/post-translations.gjs
index a97267f0485..0a4a3b23271 100644
--- a/app/assets/javascripts/discourse/app/components/modal/post-translations.gjs
+++ b/app/assets/javascripts/discourse/app/components/modal/post-translations.gjs
@@ -62,20 +62,14 @@ export default class PostTranslationsModal extends Component {
this.args.closeModal();
- const composerOpts = {
+ await this.composer.open({
action: Composer.ADD_TRANSLATION,
draftKey: "translation",
warningsDisabled: true,
hijackPreview: this.originalPostContent,
post: this.args.model.post,
selectedTranslationLocale: locale.locale,
- };
-
- if (locale?.topic_localization) {
- composerOpts.topicTitle = locale.topic_localization?.title;
- }
-
- await this.composer.open(composerOpts);
+ });
this.composer.model.set("reply", locale.raw);
}
diff --git a/app/assets/javascripts/discourse/app/components/post-language-selector.gjs b/app/assets/javascripts/discourse/app/components/post-language-selector.gjs
deleted file mode 100644
index 61960dad37f..00000000000
--- a/app/assets/javascripts/discourse/app/components/post-language-selector.gjs
+++ /dev/null
@@ -1,54 +0,0 @@
-import Component from "@glimmer/component";
-import { fn } from "@ember/helper";
-import { action } from "@ember/object";
-import { service } from "@ember/service";
-import DButton from "discourse/components/d-button";
-import DropdownMenu from "discourse/components/dropdown-menu";
-import DMenu from "float-kit/components/d-menu";
-
-export default class PostLanguageSelector extends Component {
- @service siteSettings;
-
- @action
- selectPostLanguage(locale) {
- this.args.composerModel.locale = locale;
- this.dMenu.close();
- }
-
- @action
- onRegisterApi(api) {
- this.dMenu = api;
- }
-
- <template>
- <DMenu
- @identifier="post-language-selector"
- @title="Post Language"
- @icon="globe"
- @label={{@selectedLanguage}}
- @modalForMobile={{true}}
- @onRegisterApi={{this.onRegisterApi}}
- @class="btn-transparent btn-small post-language-selector"
- >
- <:content>
- <DropdownMenu as |dropdown|>
- {{#each
- this.siteSettings.available_content_localization_locales
- as |locale|
- }}
- <dropdown.item
- class="locale=options"
- data-menu-option-id={{locale.value}}
- >
- <DButton
- @translatedLabel={{locale.name}}
- @title={{locale.value}}
- @action={{fn this.selectPostLanguage locale.value}}
- />
- </dropdown.item>
- {{/each}}
- </DropdownMenu>
- </:content>
- </DMenu>
- </template>
-}
diff --git a/app/assets/javascripts/discourse/app/components/post-translation-editor.gjs b/app/assets/javascripts/discourse/app/components/post-translation-editor.gjs
index 90ce863cb8e..e3dcd452695 100644
--- a/app/assets/javascripts/discourse/app/components/post-translation-editor.gjs
+++ b/app/assets/javascripts/discourse/app/components/post-translation-editor.gjs
@@ -5,8 +5,6 @@ import { service } from "@ember/service";
import DEditor from "discourse/components/d-editor";
import TextField from "discourse/components/text-field";
import lazyHash from "discourse/helpers/lazy-hash";
-import { popupAjaxError } from "discourse/lib/ajax-error";
-import PostLocalization from "discourse/models/post-localization";
import { i18n } from "discourse-i18n";
import DropdownSelectBox from "select-kit/components/dropdown-select-box";
@@ -14,19 +12,29 @@ export default class PostTranslationEditor extends Component {
@service composer;
@service siteSettings;
- async findCurrentLocalization() {
- try {
- const { post_localizations } = await PostLocalization.find(
- this.composer.model.post.id
+ get availableLocales() {
+ const allAvailableLocales = JSON.parse(this.siteSettings.available_locales);
+ const supportedLocales =
+ this.siteSettings.experimental_content_localization_supported_locales.split(
+ "|"
);
- return post_localizations.find(
- (localization) =>
- localization.locale === this.composer.selectedTranslationLocale
- );
- } catch (error) {
- popupAjaxError(error);
+ if (!supportedLocales.includes(this.siteSettings.default_locale)) {
+ supportedLocales.push(this.siteSettings.default_locale);
}
+
+ const filtered = allAvailableLocales.filter((locale) => {
+ return supportedLocales.includes(locale.value);
+ });
+
+ return filtered;
+ }
+
+ findCurrentLocalization() {
+ return this.composer.model.post.post_localizations.find(
+ (localization) =>
+ localization.locale === this.composer.selectedTranslationLocale
+ );
}
@action
@@ -35,25 +43,13 @@ export default class PostTranslationEditor extends Component {
}
@action
- async updateSelectedLocale(locale) {
+ updateSelectedLocale(locale) {
this.composer.selectedTranslationLocale = locale;
- const currentLocalization = await this.findCurrentLocalization();
+ const currentLocalization = this.findCurrentLocalization();
if (currentLocalization) {
this.composer.model.set("reply", currentLocalization.raw);
-
- if (currentLocalization?.topic_localization) {
- this.composer.model.set(
- "title",
- currentLocalization.topic_localization.title
- );
- }
- } else {
- this.composer.model.setProperties({
- reply: "",
- title: "",
- });
}
}
@@ -63,7 +59,7 @@ export default class PostTranslationEditor extends Component {
@nameProperty="name"
@valueProperty="value"
@value={{this.composer.selectedTranslationLocale}}
- @content={{this.siteSettings.available_content_localization_locales}}
+ @content={{this.availableLocales}}
@onChange={{this.updateSelectedLocale}}
@options={{hash
icon="globe"
diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js
index 41f93efa768..c597a7cf8de 100644
--- a/app/assets/javascripts/discourse/app/models/composer.js
+++ b/app/assets/javascripts/discourse/app/models/composer.js
@@ -73,13 +73,11 @@ const CLOSED = "closed",
shared_draft: "sharedDraft",
no_bump: "noBump",
draft_key: "draftKey",
- locale: "locale",
},
_update_serializer = {
raw: "reply",
topic_id: "topic.id",
original_text: "originalText",
- locale: "locale",
},
_edit_topic_serializer = {
title: "topic.title",
@@ -88,7 +86,6 @@ const CLOSED = "closed",
featuredLink: "topic.featured_link",
original_title: "originalTitle",
original_tags: "originalTags",
- locale: "locale",
},
_draft_serializer = {
reply: "reply",
@@ -106,7 +103,6 @@ const CLOSED = "closed",
original_text: "originalText",
original_title: "originalTitle",
original_tags: "originalTags",
- locale: "locale",
},
_add_draft_fields = {},
FAST_REPLY_LENGTH_THRESHOLD = 10000;
@@ -118,7 +114,6 @@ export const SAVE_LABELS = {
[PRIVATE_MESSAGE]: "composer.create_pm",
[CREATE_SHARED_DRAFT]: "composer.create_shared_draft",
[EDIT_SHARED_DRAFT]: "composer.save_edit",
- [ADD_TRANSLATION]: "composer.translations.save",
};
export const SAVE_ICONS = {
@@ -209,7 +204,6 @@ export default class Composer extends RestModel {
@tracked post;
@tracked reply;
@tracked whisper;
- @tracked locale = this.post?.locale || this.siteSettings.default_locale;
unlistTopic = false;
noBump = false;
@@ -1182,7 +1176,6 @@ export default class Composer extends RestModel {
typingTime: this.typingTime,
composerTime: this.composerTime,
metaData: this.metaData,
- locale: this.locale,
});
this.serialize(_create_serializer, createdPost);
diff --git a/app/assets/javascripts/discourse/app/services/composer.js b/app/assets/javascripts/discourse/app/services/composer.js
index 43bba2a4dd9..ecdc0ab2d0b 100644
--- a/app/assets/javascripts/discourse/app/services/composer.js
+++ b/app/assets/javascripts/discourse/app/services/composer.js
@@ -367,6 +367,8 @@ export default class ComposerService extends Service {
return "composer.create_whisper";
} else if (privateMessage && modelAction === Composer.REPLY) {
return "composer.create_pm";
+ } else if (modelAction === Composer.ADD_TRANSLATION) {
+ return "composer.translations.save";
}
return SAVE_LABELS[modelAction];
@@ -1385,7 +1387,6 @@ export default class ComposerService extends Service {
this.set("hijackPreview", opts.hijackPreview);
}
- // TODO: fix this not working anymore? need to use `opts.locale` instead?
if (opts.selectedTranslationLocale) {
this.selectedTranslationLocale = opts.selectedTranslationLocale;
}
@@ -1475,7 +1476,6 @@ export default class ComposerService extends Service {
action: CREATE_TOPIC,
draftKey: this.topicDraftKey,
draftSequence: 0,
- locale: this.siteSettings.default_locale,
});
}
@@ -1518,8 +1518,6 @@ export default class ComposerService extends Service {
isWarning: false,
hasTargetGroups: opts.hasGroups,
warningsDisabled: opts.warningsDisabled,
- locale:
- opts?.locale || opts?.post?.locale || this.siteSettings.default_locale,
});
if (!this.model.targetRecipients) {
diff --git a/app/assets/stylesheets/common/components/post-translations.scss b/app/assets/stylesheets/common/components/post-translations.scss
index 7f671c24a46..6c2a73197f1 100644
--- a/app/assets/stylesheets/common/components/post-translations.scss
+++ b/app/assets/stylesheets/common/components/post-translations.scss
@@ -9,15 +9,3 @@
color: var(--quaternary);
}
}
-
-.post-language-selector-content {
- z-index: z("composer", "dropdown");
-}
-
-.post-language-selector-trigger {
- margin-left: 1rem;
-
- .d-button-label {
- text-transform: uppercase;
- }
-}
diff --git a/app/controllers/post_localizations_controller.rb b/app/controllers/post_localizations_controller.rb
index 70edce0b6cf..d7a0827ee19 100644
--- a/app/controllers/post_localizations_controller.rb
+++ b/app/controllers/post_localizations_controller.rb
@@ -6,33 +6,20 @@ class PostLocalizationsController < ApplicationController
def show
guardian.ensure_can_localize_content!
- params.require(:post_id)
+ params.require(%i[post_id])
+ localizations = PostLocalization.where(post_id: params[:post_id])
- post = Post.find_by(id: params[:post_id])
- return render json_error(I18n.t("not_found"), status: :not_found) if post.blank?
-
- post_localizations = PostLocalization.where(post_id: post.id)
-
- topic_localizations_by_locale = {}
- if post.is_first_post?
- TopicLocalization
- .where(topic_id: post.topic_id)
- .each { |tl| topic_localizations_by_locale[tl.locale] = tl }
- end
-
- post_localizations.each do |pl|
- pl.define_singleton_method(:topic_localization) { topic_localizations_by_locale[pl.locale] }
- end
-
- render json: {
- post_localizations:
+ if localizations
+ render json:
ActiveModel::ArraySerializer.new(
- post_localizations,
+ localizations,
each_serializer: PostLocalizationSerializer,
root: false,
).as_json,
- },
- status: :ok
+ status: :ok
+ else
+ render json_error I18n.t("not_found"), status: :not_found
+ end
end
def create_or_update
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index 882dc0eda9c..983376edb52 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -244,11 +244,7 @@ class PostsController < ApplicationController
guardian.ensure_can_edit!(post)
- changes = {
- raw: params[:post][:raw],
- edit_reason: params[:post][:edit_reason],
- locale: params[:post][:locale],
- }
+ changes = { raw: params[:post][:raw], edit_reason: params[:post][:edit_reason] }
Post.plugin_permitted_update_params.keys.each { |param| changes[param] = params[:post][param] }
@@ -857,7 +853,6 @@ class PostsController < ApplicationController
visible
draft_key
composer_version
- locale
]
Post.plugin_permitted_create_params.each do |key, value|
diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb
index 948b892b52a..08803f0dbc3 100644
--- a/app/models/site_setting.rb
+++ b/app/models/site_setting.rb
@@ -115,20 +115,6 @@ class SiteSetting < ActiveRecord::Base
LocaleSiteSetting.values.to_json
end
- if SiteSetting.experimental_content_localization?
- client_settings << :available_content_localization_locales
- end
-
- def self.available_content_localization_locales
- supported_locales = SiteSetting.experimental_content_localization_supported_locales.split("|")
- default_locale = SiteSetting.default_locale
- if default_locale.present? && !supported_locales.include?(default_locale)
- supported_locales << default_locale
- end
-
- LocaleSiteSetting.values.select { |locale| supported_locales.include?(locale[:value]) }
- end
-
def self.topic_title_length
min_topic_title_length..max_topic_title_length
end
diff --git a/app/serializers/post_localization_serializer.rb b/app/serializers/post_localization_serializer.rb
index 07df1baa266..f63ae0366b4 100644
--- a/app/serializers/post_localization_serializer.rb
+++ b/app/serializers/post_localization_serializer.rb
@@ -1,13 +1,5 @@
# frozen_string_literal: true
class PostLocalizationSerializer < ApplicationSerializer
- attributes :id, :post_id, :post_version, :locale, :raw, :topic_localization
-
- def topic_localization
- TopicLocalizationSerializer.new(object.topic_localization, root: false).as_json
- end
-
- def include_topic_localization?
- object.respond_to?(:topic_localization) && object.topic_localization.present?
- end
+ attributes :id, :post_id, :locale, :raw
end
diff --git a/app/serializers/topic_localization_serializer.rb b/app/serializers/topic_localization_serializer.rb
deleted file mode 100644
index 230667b0da4..00000000000
--- a/app/serializers/topic_localization_serializer.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-# frozen_string_literal: true
-
-class TopicLocalizationSerializer < ApplicationSerializer
- attributes :id, :topic_id, :locale, :title, :fancy_title
-end
diff --git a/lib/post_creator.rb b/lib/post_creator.rb
index 2150322ccce..548819777bd 100644
--- a/lib/post_creator.rb
+++ b/lib/post_creator.rb
@@ -555,7 +555,6 @@ class PostCreator
via_email
raw_email
action_code
- locale
].each { |a| post.public_send("#{a}=", @opts[a]) if @opts[a].present? }
post.extract_quoted_post_numbers
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index 1c11acb670b..706588d5347 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -40,7 +40,7 @@ class PostRevisor
end
end
- POST_TRACKED_FIELDS = %w[raw cooked edit_reason user_id wiki post_type locale]
+ POST_TRACKED_FIELDS = %w[raw cooked edit_reason user_id wiki post_type]
attr_reader :category_changed, :post_revision
diff --git a/spec/system/anon_language_switcher_spec.rb b/spec/system/anon_language_switcher_spec.rb
index fafcfafd888..b80a5e9e731 100644
--- a/spec/system/anon_language_switcher_spec.rb
+++ b/spec/system/anon_language_switcher_spec.rb
@@ -14,18 +14,13 @@ RSpec.describe "Anonymous user language switcher", type: :system do
end
before do
- SiteSetting.default_locale = "en"
- SiteSetting.experimental_content_localization_supported_locales = "es|ja"
- SiteSetting.experimental_content_localization = true
SiteSetting.allow_user_locale = true
SiteSetting.set_locale_from_cookie = true
-
- if SiteSetting.client_settings.exclude?(:available_content_localization_locales)
- SiteSetting.client_settings << :available_content_localization_locales
- end
end
it "only shows the language switcher based on what is in target languages" do
+ SiteSetting.experimental_content_localization_supported_locales = "es|ja"
+
SiteSetting.experimental_anon_language_switcher = false
visit("/")
@@ -35,7 +30,6 @@ RSpec.describe "Anonymous user language switcher", type: :system do
visit("/")
switcher.expand
- expect(switcher).to have_content("English (US)")
expect(switcher).to have_content("日本語")
expect(switcher).to have_content("Español")
diff --git a/spec/system/edit_category_localizations_spec.rb b/spec/system/edit_category_localizations_spec.rb
index 6e03355cf24..2ee998df0b6 100644
--- a/spec/system/edit_category_localizations_spec.rb
+++ b/spec/system/edit_category_localizations_spec.rb
@@ -20,16 +20,7 @@ describe "Edit Category Localizations", type: :system do
end
context "when content localization setting is enabled" do
- before do
- SiteSetting.default_locale = "en"
- SiteSetting.experimental_content_localization = true
- SiteSetting.experimental_content_localization_supported_locales = "es|fr"
- SiteSetting.experimental_content_localization_allowed_groups = Group::AUTO_GROUPS[:everyone]
-
- if SiteSetting.client_settings.exclude?(:available_content_localization_locales)
- SiteSetting.client_settings << :available_content_localization_locales
- end
- end
+ before { SiteSetting.experimental_content_localization = true }
it "should show the localization tab" do
category_page.visit_settings(category)
diff --git a/spec/system/post_translation_spec.rb b/spec/system/post_translation_spec.rb
index 0eae42b9230..b3044d2b81c 100644
--- a/spec/system/post_translation_spec.rb
+++ b/spec/system/post_translation_spec.rb
@@ -13,19 +13,15 @@ describe "Post translations", type: :system do
before do
sign_in(user)
- SiteSetting.default_locale = "en"
- SiteSetting.experimental_content_localization_supported_locales = "fr|es|pt_BR"
+ SiteSetting.experimental_content_localization_supported_locales = "en|fr|es|pt_BR"
SiteSetting.experimental_content_localization = true
SiteSetting.experimental_content_localization_allowed_groups = Group::AUTO_GROUPS[:everyone]
- if SiteSetting.client_settings.exclude?(:available_content_localization_locales)
- SiteSetting.client_settings << :available_content_localization_locales
- end
SiteSetting.post_menu =
"read|like|copyLink|flag|edit|bookmark|delete|admin|reply|addTranslation"
end
context "when a post does not have translations" do
- it "should only show the languages listed in the site setting and the default locale" do
+ it "should only show the languages listed in the site setting" do
topic_page.visit_topic(topic)
find("#post_#{post.post_number} .post-action-menu__add-translation").click
translation_selector.expand
@@ -38,11 +34,12 @@ describe "Post translations", type: :system do
end
it "always includes the site's default locale in the list of available languages" do
+ SiteSetting.default_locale = "de"
topic_page.visit_topic(topic)
find("#post_#{post.post_number} .post-action-menu__add-translation").click
translation_selector.expand
- expect(all(".translation-selector-dropdown .select-kit-collection li").count).to eq(4)
- expect(translation_selector).to have_option_value("en")
+ expect(all(".translation-selector-dropdown .select-kit-collection li").count).to eq(5)
+ expect(translation_selector).to have_option_value("de")
end
it "allows a user to translate a post" do