Skip to content

Commit 1c003d8

Browse files
committed
FEATURE: Show full topic translations
1 parent 113acae commit 1c003d8

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

config/locales/server.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ en:
2020
experimental_anon_language_switcher: "Enable experimental language switcher for anonymous users. This will allow anonymous users to switch between translated versions of Discourse and user-contributed content in topics."
2121
errors:
2222
set_locale_cookie_requirements: "The experimental language switcher for anonymous users requires the `set locale from cookie` site setting to be enabled."
23+
experimental_topic_translation: "Enable experimental topic translation feature. This replaces existing post in-line translation with a button that allows users to translate the entire topic."
2324
translator:
2425
failed: "The translator is unable to translate this content (%{source_locale}) to the default language of this site (%{target_locale})."
2526
not_supported: "This language is not supported by the translator."

config/settings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ discourse_translator:
106106
default: false
107107
client: true
108108
validator: "LanguageSwitcherSettingValidator"
109+
experimental_topic_translation:
110+
default: false
111+
client: true

plugin.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,17 @@ module ::DiscourseTranslator
4747
add_to_serializer :post, :can_translate do
4848
scope.can_translate?(object)
4949
end
50+
51+
add_to_class :post, :has_translation? do |language|
52+
translated = custom_fields[::DiscourseTranslator::TRANSLATED_CUSTOM_FIELD]
53+
!(language.blank? || translated.blank? || translated[language].blank?)
54+
end
55+
56+
add_to_serializer :post, :cooked, false do
57+
return super() if !SiteSetting.experimental_topic_translation
58+
return super() if scope.request.params["show-original"].present?
59+
return super() if !object.has_translation?(I18n.locale)
60+
translated = object.custom_fields[::DiscourseTranslator::TRANSLATED_CUSTOM_FIELD]
61+
translated[I18n.locale]
62+
end
5063
end

0 commit comments

Comments
 (0)