diff --git a/app/assets/stylesheets/locale.scss b/app/assets/stylesheets/locale.scss new file mode 100644 index 0000000..bf5fdc0 --- /dev/null +++ b/app/assets/stylesheets/locale.scss @@ -0,0 +1,17 @@ +li.locale { + padding-top: 10px; +} + +span.locale { + background: grey; + padding: 0.3em 10px 0.3em 10px; + text-align: center; + color: white; + cursor: pointer; + border-radius: 5px; + margin-top: 10px; +} + +span.locale:hover { + background: #eee; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d00fd5e..1dec6a9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,9 +2,24 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + before_action :set_locale + + private + + def set_locale + I18n.locale = params[:locale] || I18n.default_locale + end protected + def self.default_url_options(options={}) + if I18n.locale != I18n.default_locale + options.merge({locale: I18n.locale}) + else + options + end + end + def current_ip_address # request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 00a62e7..5f355d7 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -23,7 +23,27 @@
  • <%= t 'generic.press_submit' %>
  • + + <% unless I18n.locale == :en %> +
  • + <%= link_to url_for(request.query_parameters.merge(locale: 'en')), hreflang: 'en' do %> + + + + <% end %> +
  • + <% end %> + <% unless I18n.locale == :bg %> +
  • + <%= link_to url_for(request.query_parameters.merge(locale: 'bg')), hreflang: 'bg' do %> + + + + <% end %> +
  • + <% end %> +
    diff --git a/config/application.rb b/config/application.rb index bea26da..43f2506 100644 --- a/config/application.rb +++ b/config/application.rb @@ -18,7 +18,8 @@ module Gauge # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de + config.i18n.available_locales = [:bg, :en] + config.i18n.default_locale = :bg # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true diff --git a/config/locales/bg.yml b/config/locales/bg.yml new file mode 100644 index 0000000..7ae1466 --- /dev/null +++ b/config/locales/bg.yml @@ -0,0 +1,9 @@ +bg: + generic: + title: Гласуване за лекции на OpenFest 2015 + submit: Изпрати + store_and_submit_changes: Запази локално промените и ги изпрати, ако е възможно + help_us_reduce_the_conflicts: Помогнете ни да намалим конфликтите в програмата на OpenFest + click_on_the_talks_you_would_like_to_watch: Кликнете върху лекциите, които искате да посетите. + press_submit: Натиснете „Изпрати“. + filter_events: Търсене