-
Notifications
You must be signed in to change notification settings - Fork 52
FIX: 'Show original' button only shows in topics where there are translated content #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| locale = DiscourseTranslator::InlineTranslation.effective_locale | ||
| return false if post.locale_matches?(locale) | ||
| post.translation_for(locale).nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When in experimental_inline_translation, we only want to allow a user to translate a post if the user's locale is within the target languages that we support for the site (effective_locale).
| # since locales are eager loaded but translations may not, | ||
| # always return early if topic and posts are in the user's effective_locale. | ||
| # this prevents the need to load translations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All plugin api usages will check for locale first.
| plugin.add_to_serializer(:basic_post, :is_translated) do | ||
| SiteSetting.experimental_inline_translation && | ||
| !object.locale_matches?(InlineTranslation.effective_locale) && | ||
| object.translation_for(InlineTranslation.effective_locale).present? | ||
| end | ||
|
|
||
| plugin.add_to_serializer(:topic_view, :is_translated) do | ||
| SiteSetting.experimental_inline_translation && | ||
| !object.topic.locale_matches?(InlineTranslation.effective_locale) && | ||
| object.topic.translation_for(InlineTranslation.effective_locale).present? | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two flags are used in the frontend to check if a topic is showing translated content
| end | ||
|
|
||
| def self.user_locale_is_default? | ||
| # e.g. :en_UK vs "en_UK" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Currently, the button above shows up even when there are no posts translated. With this PR, we will not show the button if there are zero posts in the topic that is translated.
This PR also
SiteSetting.automatic_translation_target_languages)