Skip to content

Conversation

@nattsw
Copy link
Contributor

@nattsw nattsw commented Mar 4, 2025

Screenshot 2025-03-04 at 4 47 25 PM

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

  • only returns translations of supported languages (in SiteSetting.automatic_translation_target_languages)
  • optimises loading translations when the feature is enabled under certain circumstances

Comment on lines +33 to +35
locale = DiscourseTranslator::InlineTranslation.effective_locale
return false if post.locale_matches?(locale)
post.translation_for(locale).nil?
Copy link
Contributor Author

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).

Comment on lines +14 to +16
# 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.
Copy link
Contributor Author

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.

Comment on lines +57 to +67
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
Copy link
Contributor Author

@nattsw nattsw Mar 5, 2025

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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@nattsw nattsw merged commit 00a202f into main Mar 6, 2025
6 checks passed
@nattsw nattsw deleted the hide-show-ori-no-trans branch March 6, 2025 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants