discourse-translator/lib/discourse_translator/locale_matcher.rb
Natalie Tay 00a202feb6
FIX: 'Show original' button only shows in topics where there are translated content (#240)
Currently, the button above shows up even when there are no posts translated. With this commit, we will not show the button if there are zero posts in the topic that is translated.

This commit also
- only returns translations of supported languages (in SiteSetting.automatic_translation_target_languages)
- optimises loading translations when the feature is enabled under certain circumstances
2025-03-06 11:36:44 +08:00

15 lines
406 B
Ruby

# frozen_string_literal: true
module DiscourseTranslator
class LocaleMatcher
def self.user_locale_in_target_languages?
# e.g. "en|es|pt_BR" vs :en_UK
SiteSetting.automatic_translation_target_languages.split("|").include?(I18n.locale.to_s)
end
def self.user_locale_is_default?
# e.g. :en_UK vs "en_UK"
I18n.locale.to_s == SiteSetting.default_locale
end
end
end