Skip to content

Commit

Permalink
Add a default cookie for the translation to appear when no translatio…
Browse files Browse the repository at this point in the history
…n had been selected
  • Loading branch information
AyakorK committed Nov 3, 2023
1 parent 825e8e9 commit fae1382
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ def auto_target_language
if Rails.application.secrets.dig(:decidim, :translation_mode).to_sym == :both && response.headers["content-language"].present?
response.headers["content-language"].split("-").first
end

if translation_mode?(:google)
default_trad = Rails.configuration.i18n.default_locale.to_s
cookies[:googtrans] ||= { value: "/auto/#{default_trad}", expires: 1.year.from_now }
end
end
end
5 changes: 0 additions & 5 deletions app/views/layouts/decidim/_head_extra.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<% end %>
<% if translation_mode?(:google) %>
<script>

const pageLanguage = 'en';
const autoTargetLanguage = '<%= auto_target_language %>';

function waitForElm(selector) {
Expand All @@ -34,9 +32,6 @@

function googleTranslateElementInit() {
new google.translate.TranslateElement(
{
pageLanguage: autoTargetLanguage
},
'google_translate_element'
);
}
Expand Down

0 comments on commit fae1382

Please sign in to comment.