Files
nairobi/app/controllers/concerns/remotely_translatable.rb
taitus 2f500a6b56 Fix detect_remote_translations for Legislation::Proposal
Legislation::Proposal is not Globalize model but use CommentableActions and try
detect remote translations. Add new condition to discard Non Globalize models.
This fix is necessary since the following commit was included: c1f3a4ad.
2020-02-26 16:47:13 +01:00

32 lines
968 B
Ruby

module RemotelyTranslatable
private
def detect_remote_translations(*args)
return [] unless Setting["feature.remote_translations"].present? && api_key_has_been_set_in_secrets?
resources_groups(*args).flatten.select { |resource| translation_empty?(resource) }.map do |resource|
remote_translation_for(resource)
end
end
def remote_translation_for(resource)
{ "remote_translatable_id" => resource.id.to_s,
"remote_translatable_type" => resource.class.to_s,
"locale" => I18n.locale }
end
def translation_empty?(resource)
resource.class.translates? && resource.translations.where(locale: I18n.locale).empty?
end
def resources_groups(*args)
feeds = args.find { |arg| arg&.first.class == Widget::Feed } || []
args.compact - [feeds] + feeds.map(&:items)
end
def api_key_has_been_set_in_secrets?
Rails.application.secrets.microsoft_api_key.present?
end
end