It has been detected that for the :pt-BR, :zh-CN and :zh-TW locales,
the translate button was being displayed, but when requesting the
translation, the remote translation validation failed due to:
'''
validates :locale, inclusion: { in: ->(_) {
RemoteTranslations::Microsoft::AvailableLocales.available_locales }}
'''
That available_locales method did not contemplate these 3 languages
in the format used by the application.
To solve this problem the api response is mapped to return all
locales in the format expected by the application.
Add remote translation model test to ensure that a remote translation
is valid when its locale is pt-BR.
Co-Authored-By: Javi Martín <35156+javierm@users.noreply.github.com>
66 lines
2.3 KiB
Ruby
66 lines
2.3 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Layout::RemoteTranslationsButtonComponent do
|
|
let(:translations) { [RemoteTranslation.new] }
|
|
let(:component) { Layout::RemoteTranslationsButtonComponent.new(translations) }
|
|
|
|
before do
|
|
allow(RemoteTranslations::Microsoft::AvailableLocales).to receive(:remote_available_locales)
|
|
.and_return(%w[de en es fr pt zh-Hans])
|
|
end
|
|
|
|
context "locale with English as a fallback" do
|
|
before do
|
|
allow(I18n.fallbacks).to receive(:[]).and_return([:en])
|
|
Globalize.set_fallbacks_to_all_available_locales
|
|
end
|
|
|
|
it "displays the text in English" do
|
|
I18n.with_locale(:de) { render_inline component }
|
|
|
|
expect(page).to have_css ".remote-translations-button"
|
|
expect(page).to have_content "The content of this page is not available in your language"
|
|
end
|
|
|
|
it "displays the text in English with a locale needing parsing" do
|
|
I18n.with_locale(:"zh-CN") { render_inline component }
|
|
|
|
expect(page).to have_css ".remote-translations-button"
|
|
expect(page).to have_content "The content of this page is not available in your language"
|
|
end
|
|
end
|
|
|
|
context "locale with Spanish as a fallback" do
|
|
before do
|
|
allow(I18n.fallbacks).to receive(:[]).and_return([:es])
|
|
Globalize.set_fallbacks_to_all_available_locales
|
|
end
|
|
|
|
it "displays the text in Spanish" do
|
|
I18n.with_locale(:fr) { render_inline component }
|
|
|
|
expect(page).to have_css ".remote-translations-button"
|
|
expect(page).to have_content "El contenido de esta página no está disponible en tu idioma"
|
|
end
|
|
|
|
it "displays the text in Spanish with a locale needing parsing" do
|
|
I18n.with_locale(:"pt-BR") { render_inline component }
|
|
|
|
expect(page).to have_css ".remote-translations-button"
|
|
expect(page).to have_content "El contenido de esta página no está disponible en tu idioma"
|
|
end
|
|
end
|
|
|
|
it "is not rendered when the locale isn't included in microsoft translate client" do
|
|
I18n.with_locale(:nl) { render_inline component }
|
|
|
|
expect(page).not_to be_rendered
|
|
end
|
|
|
|
it "is not rendered when there aren't any remote translations" do
|
|
render_inline Layout::RemoteTranslationsButtonComponent.new([])
|
|
|
|
expect(page).not_to be_rendered
|
|
end
|
|
end
|