mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 00:20:20 +08:00
This PR takes the localization features out of "experimental" to prep for the announcement - rename settings and gives them its own area - `experimental_content_localization` to `content_localization_enabled` - `experimental_content_localization_allowed_groups` to `content_localization_allowed_groups` - `experimental_content_localization_supported_locales` to `content_localization_supported_locales` - `experimental_anon_language_switcher` to `content_localization_anon_language_switcher` - migration - related to https://github.com/discourse/discourse-ai/pull/1439 | screenshot 📸 | |---| | <img width="964" alt="Screenshot 2025-06-17 at 5 06 32 PM" src="https://github.com/user-attachments/assets/9a8b2c38-c846-4fc9-8ddd-815c45cc3d0e" /> |
29 lines
1.2 KiB
Ruby
29 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ContentLocalization
|
|
SHOW_ORIGINAL_COOKIE = "content-localization-show-original"
|
|
|
|
# @param scope [Object] The serializer scope from which the method is called
|
|
# @return [Boolean] if the cookie is set, false otherwise
|
|
def self.show_original?(scope)
|
|
scope&.request&.cookies&.key?(SHOW_ORIGINAL_COOKIE)
|
|
end
|
|
|
|
# This method returns true when we should try to show the translated post.
|
|
# @param scope [Object] The serializer scope from which the method is called
|
|
# @param post [Post] The post object
|
|
# @return [Boolean]
|
|
def self.show_translated_post?(post, scope)
|
|
SiteSetting.content_localization_enabled && post.raw.present? && post.locale.present? &&
|
|
!post.in_user_locale? && !show_original?(scope)
|
|
end
|
|
|
|
# This method returns true when we should try to show the translated topic.
|
|
# @param scope [Object] The serializer scope from which the method is called
|
|
# @param topic [Topic] The topic record
|
|
# @return [Boolean]
|
|
def self.show_translated_topic?(topic, scope)
|
|
SiteSetting.content_localization_enabled && topic.locale.present? && !topic.in_user_locale? &&
|
|
!show_original?(scope)
|
|
end
|
|
end
|