Mattias Bodlund 1 year ago
parent
commit
86b65c49ce
4 changed files with 55 additions and 6 deletions
  1. +32
    -1
      app/assets/stylesheets/application.css
  2. +6
    -0
      app/javascript/application.js
  3. +9
    -3
      app/views/languages/index.html.erb
  4. +8
    -2
      app/views/layouts/application.html.erb

+ 32
- 1
app/assets/stylesheets/application.css View File

@ -694,4 +694,35 @@ ul.card__stack {
.icon__container img:nth-child(4) { .icon__container img:nth-child(4) {
display: block; display: block;
} }
}
}
[data-locale] {
display: none;
}
html[lang="en"] [data-locale='en'],
html[lang="zh"] [data-locale='zh'],
html[lang="hr"] [data-locale='hr'],
html[lang="cs"] [data-locale='cs'],
html[lang="da"] [data-locale='da'],
html[lang="nl"] [data-locale='nl'],
html[lang="fi"] [data-locale='fi'],
html[lang="fr"] [data-locale='fr'],
html[lang="fr-CA"] [data-locale='fr-CA'],
html[lang="de"] [data-locale='de'],
html[lang="hu"] [data-locale='hu'],
html[lang="it"] [data-locale='it'],
html[lang="ja"] [data-locale='ja'],
html[lang="ko"] [data-locale='ko'],
html[lang="nb"] [data-locale='nb'],
html[lang="pl"] [data-locale='pl'],
html[lang="pt"] [data-locale='pt'],
html[lang="ro"] [data-locale='ro'],
html[lang="sr"] [data-locale='sr'],
html[lang="sk"] [data-locale='sk'],
html[lang="sl"] [data-locale='sl'],
html[lang="es"] [data-locale='es'],
html[lang="sv"] [data-locale='sv'],
html[lang="uk"] [data-locale='uk'] {
display: revert;
}

+ 6
- 0
app/javascript/application.js View File

@ -80,6 +80,12 @@ function init() {
shuffle_cards() shuffle_cards()
}) })
document.querySelectorAll('#language_select').forEach((language_select) => {
language_select.addEventListener('change', (e) => {
document.documentElement.lang = language_select.value
})
})
// Choose language confirmation button // Choose language confirmation button
document.querySelectorAll('#confirm_btn').forEach((confirm_btn) => { document.querySelectorAll('#confirm_btn').forEach((confirm_btn) => {
confirm_btn.addEventListener('click', (e) => { confirm_btn.addEventListener('click', (e) => {


+ 9
- 3
app/views/languages/index.html.erb View File

@ -1,16 +1,22 @@
<%- content_for :title, t('project_name') %> <%- content_for :title, t('project_name') %>
<div class="msg__container msg__container-language"> <div class="msg__container msg__container-language">
<%= tag.h1 t('hello', locale: accept_language) %>
<% I18n.available_locales.each do |l| %>
<%= tag.h1 t('hello', locale: l), data: {locale: l} %>
<% end %>
<%= tag.div t('please_select_a_language_to_get_started', locale: accept_language) %>
<% I18n.available_locales.each do |l| %>
<%= tag.div t('please_select_a_language_to_get_started', locale: l), data: {locale: l} %>
<% end %>
<div class="form__container"> <div class="form__container">
<div class="language__selector-select"> <div class="language__selector-select">
<%= select_tag :language, options_for_select(languages_for_select, accept_language), id: 'language_select' %> <%= select_tag :language, options_for_select(languages_for_select, accept_language), id: 'language_select' %>
</div> </div>
<button type="button" class="button__base" id="confirm_btn"> <button type="button" class="button__base" id="confirm_btn">
<%= t 'confirm', locale: accept_language %>
<% I18n.available_locales.each do |l| %>
<%= tag.span t('confirm', locale: l), data: {locale: l} %>
<% end %>
</button> </button>
</div> </div>
</div> </div>

+ 8
- 2
app/views/layouts/application.html.erb View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="<%= I18n.locale %>">
<html lang="<%= controller_name == 'languages' ? accept_language : I18n.locale %>">
<head> <head>
<title><%= content_for?(:title) ? yield(:title) : t(:project_name) %></title> <title><%= content_for?(:title) ? yield(:title) : t(:project_name) %></title>
@ -18,7 +18,13 @@
<header> <header>
<%= link_to svg('ikea-foundation-logo'), root_url %> <%= link_to svg('ikea-foundation-logo'), root_url %>
<div> <div>
<%= t('can_you_spot_the_link').html_safe %>
<% if controller_name == 'languages' %>
<% I18n.available_locales.each do |l| %>
<%= tag.div t('can_you_spot_the_link', locale: l).html_safe, data: {locale: l} %>
<% end %>
<% else %>
<%= t('can_you_spot_the_link').html_safe %>
<% end %>
</div> </div>
</header> </header>


Loading…
Cancel
Save