Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .discourse-compatibility
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
< 3.5.0.beta6-dev: 7e0a51707f98eb8ec49fa39c519075b1766d54be
< 3.5.0.beta5-dev: 5c44f829ef82ded3416b0cddc521e9e6d62ed534
< 3.5.0.beta4-dev: 14ca3c07efa0a80712a4cbb8ca455c32a727adec
< 3.5.0.beta2-dev: 5f24835801fdc7cb98e1bcf42d2ab2e49e609921
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/regular/detect_translate_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def execute(args)
return
end

locales = SiteSetting.automatic_translation_target_languages.split("|")
locales = SiteSetting.experimental_content_localization_supported_locales.split("|")
return if locales.blank?

locales.each do |locale|
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/regular/detect_translate_topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def execute(args)
return
end

locales = SiteSetting.automatic_translation_target_languages.split("|")
locales = SiteSetting.experimental_content_localization_supported_locales.split("|")
return if locales.blank?

locales.each do |locale|
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/regular/translate_categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def execute(args)
return unless SiteSetting.translator_enabled
return unless SiteSetting.experimental_content_translation

locales = SiteSetting.automatic_translation_target_languages.split("|")
locales = SiteSetting.experimental_content_localization_supported_locales.split("|")
return if locales.blank?

cat_id = args[:from_category_id] || Category.order(:id).first&.id
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/regular/translate_posts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def execute(args)
return unless SiteSetting.translator_enabled
return unless SiteSetting.experimental_content_translation

locales = SiteSetting.automatic_translation_target_languages.split("|")
locales = SiteSetting.experimental_content_localization_supported_locales.split("|")
return if locales.blank?

limit = args[:limit] || BATCH_SIZE
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/regular/translate_topics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def execute(args)
return unless SiteSetting.translator_enabled
return unless SiteSetting.experimental_content_translation

locales = SiteSetting.automatic_translation_target_languages.split("|")
locales = SiteSetting.experimental_content_localization_supported_locales.split("|")
return if locales.blank?

limit = args[:limit] || BATCH_SIZE
Expand Down
3 changes: 1 addition & 2 deletions app/jobs/scheduled/category_translation_backfill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def execute(args)
return unless SiteSetting.translator_enabled
return unless SiteSetting.experimental_content_translation

locales = SiteSetting.automatic_translation_target_languages.split("|")
return if locales.blank?
return if SiteSetting.experimental_content_localization_supported_locales.blank?

Jobs.enqueue(:translate_categories)
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/scheduled/post_translation_backfill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def execute(args)
return unless SiteSetting.translator_enabled
return unless SiteSetting.experimental_content_translation

return if SiteSetting.automatic_translation_target_languages.blank?
return if SiteSetting.experimental_content_localization_supported_locales.blank?
return if SiteSetting.automatic_translation_backfill_rate == 0

Jobs.enqueue(:translate_posts, limit: SiteSetting.automatic_translation_backfill_rate)
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/scheduled/topic_translation_backfill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def execute(args)
return unless SiteSetting.translator_enabled
return unless SiteSetting.experimental_content_translation

return if SiteSetting.automatic_translation_target_languages.blank?
return if SiteSetting.experimental_content_localization_supported_locales.blank?
return if SiteSetting.automatic_translation_backfill_rate == 0

Jobs.enqueue(:translate_topics, limit: SiteSetting.automatic_translation_backfill_rate)
Expand Down
67 changes: 0 additions & 67 deletions assets/javascripts/discourse/components/language-switcher.gjs

This file was deleted.

59 changes: 0 additions & 59 deletions assets/javascripts/discourse/components/show-original-content.gjs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { withPluginApi } from "discourse/lib/plugin-api";
import LanguageSwitcher from "../components/language-switcher";
import ToggleTranslationButton from "../components/post-menu/toggle-translation-button";
import TranslatedPost from "../components/translated-post";

Expand All @@ -9,20 +8,6 @@ function initializeTranslation(api) {
return;
}

const currentUser = api.getCurrentUser();

if (
!currentUser &&
siteSettings.experimental_anon_language_switcher &&
siteSettings.automatic_translation_target_languages
) {
api.headerIcons.add(
"discourse-translator_language-switcher",
LanguageSwitcher,
{ before: ["search"] }
);
}

customizePostMenu(api);
}

Expand Down
5 changes: 0 additions & 5 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ en:
translator_azure_custom_subdomain: "Required if using a Virtual Network or Firewall for Azure Cognitive Services. Note: Only enter the custom subdomain not the full custom endpoint."
restrict_translation_by_group: "Only allowed groups can translate"
restrict_translation_by_poster_group: "Only allow translation of posts made by users in allowed groups. If empty, allow translations of posts from all users."
experimental_anon_language_switcher: "Enable experimental language switcher. This will allow site visitors who are not logged in to switch between translated versions of Discourse and user-contributed content in topics."
errors:
needs_nonzero_backfill: "Automatic language translation requires the 'automatic_translation_backfill_rate' hidden setting to be a non-zero value. Please approach your site administrator to increase this limit."
experimental_anon_language_switcher_requirements: "The experimental language switcher requires the `set locale from cookie` site setting to be enabled, and the `automatic translation target languages` to have at least one language."
automatic_translation_target_languages: "The languages to automatically translate user content (posts, topics) to. If empty, no languages will be automatically translated."
translator:
failed:
topic: "The translator is unable to translate this topic's title (%{source_locale}) to your language (%{target_locale})."
Expand Down
12 changes: 0 additions & 12 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ discourse_translator:
- Yandex
- LibreTranslate
validator: "DiscourseTranslator::Validators::TranslatorSelectionValidator"
automatic_translation_target_languages:
default: ""
type: list
client: true
list_type: named
allow_any: false
choices: "DiscourseTranslator::TranslatableLanguagesSetting.values"
validator: "DiscourseTranslator::Validators::TranslatableLanguagesValidator"
automatic_translation_backfill_rate:
default: 0
client: false
Expand Down Expand Up @@ -122,10 +114,6 @@ discourse_translator:
default: ""
client: true
type: group_list
experimental_anon_language_switcher:
default: false
client: true
validator: "DiscourseTranslator::Validators::LanguageSwitcherSettingValidator"
experimental_content_translation:
default: false
hidden: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

class RenameTranslationTargetLanguagesToContentLocalizationSupportedLocales < ActiveRecord::Migration[
7.2
]
def up
setting_exists =
DB.query_single(
"SELECT 1 FROM site_settings WHERE name = 'experimental_content_localization_supported_locales' LIMIT 1",
).present?

if setting_exists
execute "DELETE FROM site_settings WHERE name = 'automatic_translation_target_languages'"
else
execute "UPDATE site_settings SET name = 'experimental_content_localization_supported_locales' WHERE name = 'automatic_translation_target_languages'"
end
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
10 changes: 2 additions & 8 deletions lib/discourse_translator/parallel_text_translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@
module DiscourseTranslator
class ParallelTextTranslation
def inject(plugin)
# in parallel text translations,
# we don't want to send the post for detection if automatic translation already happens,
# as automatic translations send content for language detection as a side effect of translating

plugin.on(:post_process_cooked) do |_, post|
if SiteSetting.automatic_translation_target_languages.blank? &&
Guardian.new.can_detect_language?(post) && post.user_id > 0
if Guardian.new.can_detect_language?(post) && post.user_id > 0
Jobs.enqueue(:detect_translatable_language, type: "Post", translatable_id: post.id)
end
end

plugin.on(:topic_created) do |topic|
if SiteSetting.automatic_translation_target_languages.blank? &&
Guardian.new.can_detect_language?(topic.first_post) && topic.user_id > 0
if Guardian.new.can_detect_language?(topic.first_post) && topic.user_id > 0
Jobs.enqueue(:detect_translatable_language, type: "Topic", translatable_id: topic.id)
end
end
Expand Down

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions spec/jobs/detect_translate_post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SiteSetting.translator_enabled = true
SiteSetting.experimental_content_translation = true
SiteSetting.automatic_translation_backfill_rate = 1
SiteSetting.automatic_translation_target_languages = locales.join("|")
SiteSetting.experimental_content_localization_supported_locales = locales.join("|")
end

it "does nothing when translator is disabled" do
Expand Down Expand Up @@ -45,7 +45,7 @@
end

it "does not translate when no target languages are configured" do
SiteSetting.automatic_translation_target_languages = ""
SiteSetting.experimental_content_localization_supported_locales = ""
DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(post).returns("en")
DiscourseTranslator::PostTranslator.expects(:translate).never

Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/detect_translate_topic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SiteSetting.translator_enabled = true
SiteSetting.experimental_content_translation = true
SiteSetting.automatic_translation_backfill_rate = 1
SiteSetting.automatic_translation_target_languages = locales.join("|")
SiteSetting.experimental_content_localization_supported_locales = locales.join("|")
end

it "does nothing when translator is disabled" do
Expand Down Expand Up @@ -45,7 +45,7 @@
end

it "does not translate when no target languages are configured" do
SiteSetting.automatic_translation_target_languages = ""
SiteSetting.experimental_content_localization_supported_locales = ""
DiscourseTranslator::TopicLocaleDetector.expects(:detect_locale).with(topic).returns("en")
DiscourseTranslator::TopicTranslator.expects(:translate).never

Expand Down
Loading
Loading