Improve display remote translation button
- Do not display remote translations button when API key is not configured
This commit is contained in:
@@ -2,7 +2,7 @@ module RemotelyTranslatable
|
||||
private
|
||||
|
||||
def detect_remote_translations(*args)
|
||||
return [] unless Setting["feature.remote_translations"].present?
|
||||
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)
|
||||
@@ -24,4 +24,8 @@ module RemotelyTranslatable
|
||||
|
||||
args.compact - [feeds] + feeds.map(&:items)
|
||||
end
|
||||
|
||||
def api_key_has_been_set_in_secrets?
|
||||
Rails.application.secrets.microsoft_api_key.present?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ include RemotelyTranslatable
|
||||
describe RemotelyTranslatable do
|
||||
before do
|
||||
Setting["feature.remote_translations"] = true
|
||||
allow(Rails.application.secrets).to receive(:microsoft_api_key).and_return("123")
|
||||
end
|
||||
|
||||
describe "#detect_remote_translations" do
|
||||
@@ -48,6 +49,16 @@ describe RemotelyTranslatable do
|
||||
end
|
||||
end
|
||||
|
||||
it "When api key has not been set in secrets should not detect remote_translations" do
|
||||
allow(Rails.application.secrets).to receive(:microsoft_api_key).and_return(nil)
|
||||
proposal = create(:proposal)
|
||||
comment = create(:comment, commentable: proposal)
|
||||
|
||||
I18n.with_locale(:es) do
|
||||
expect(detect_remote_translations([proposal, comment])).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
it "When defined in current locale should not detect remote_translations" do
|
||||
proposal = create(:proposal)
|
||||
comment = create(:comment, commentable: proposal)
|
||||
|
||||
@@ -7,6 +7,7 @@ describe "Remote Translations" do
|
||||
available_locales_response = %w[de en es fr pt zh-Hans]
|
||||
expect(RemoteTranslations::Microsoft::AvailableLocales).to receive(:available_locales).
|
||||
and_return(available_locales_response)
|
||||
allow(Rails.application.secrets).to receive(:microsoft_api_key).and_return("123")
|
||||
end
|
||||
|
||||
describe "Display remote translation button when locale is included in microsoft translate client" do
|
||||
|
||||
@@ -12,6 +12,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
||||
available_locales_response = %w[de en es fr pt zh-Hans]
|
||||
expect(RemoteTranslations::Microsoft::AvailableLocales).to receive(:available_locales).at_most(3).times.
|
||||
and_return(available_locales_response)
|
||||
allow(Rails.application.secrets).to receive(:microsoft_api_key).and_return("123")
|
||||
end
|
||||
|
||||
context "Button to request remote translation" do
|
||||
|
||||
Reference in New Issue
Block a user