Skip to content

Commit

Permalink
fix language selector and belive
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Jul 22, 2024
1 parent 1d92bf9 commit 669d21c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
5 changes: 4 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class ApplicationController < ActionController::Base

def change_locale
origin_url = request.referer || request.origin

uri = URI.parse(origin_url)
query_params = Rack::Utils.parse_nested_query(uri.query)

Expand Down Expand Up @@ -57,4 +56,8 @@ def render_error(title_key, body_key, status = :bad_request)
body: translate("devise.failure.#{body_key}") },
:status => status
end

def default_url_options
{ locale: I18n.locale }
end
end
8 changes: 4 additions & 4 deletions app/helpers/auth_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def devise?
end

def language_selector
test = I18n.available_locales.map do |locale|
[I18n.t(locale, scope: 'language'), locale]
languages = I18nData.languages(I18n.locale).to_a.map do |e|
[e.second.titleize, e.first.downcase.to_sym]
end
options_for_select(test, I18n.locale)
languages = languages.select { |e| I18n.available_locales.include? e.second }
options_for_select(languages, I18n.locale)
end

end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%ul.navbar.text-gray
-# Language selector
%li.d-flex.align-items-center.cursor-pointer.border-start.border-end.h-100.ps-2.pe-2
= form_with url: change_locale_path, method: :post, local: true do |f|
= form_with url: "/change_locale", method: :post, local: true do |f|
= f.select :locale, language_selector, {}, onchange: 'this.form.submit();', class: "form-control"
-# Devise/Mockdata
- if Rails.env.development?
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Application < Rails::Application
# Skip views, helpers and assets when generating a new resource.
config.autoload_paths += %W( #{config.root}/app/uploaders) #
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
I18n.available_locales = [:de, :en]
I18n.available_locales = [:de, :en, :fr]
config.i18n.default_locale = :de

config.active_record.verify_foreign_keys_for_fixtures = false
Expand Down
5 changes: 5 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ de:
other: Funktionen
picture: Bild
title: Abschluss
department: Organisationseinheit
birthdate: Geburtsdatum
nationality: Nationalität
marital_status: Zivilstand
shortname: Kurzname
project:
description: Beschreibung
role: Rolle und Aufgaben
Expand Down
7 changes: 6 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ en:
other: Functions
picture: Image
title: Conclusion
department: Department
birthdate: Birthdate
nationality: Nationality
marital_status: Marital status
shortname: Short name
project:
description: Description
role: Role and tasks
Expand All @@ -42,7 +47,7 @@ en:
category: Category
models:
activity: Station
advanced_training: Further training
advanced_training: Advanced training
company:
one: Company
other: Companies
Expand Down
5 changes: 5 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ fr:
other: Fonctions
picture: Image
title: Conclusion
department: Département
birthdate: Date de naissance
nationality: Nationalité
marital_status: Statut marital
shortname: Nom court
project:
description: Description
role: Rôle et tâches
Expand Down

0 comments on commit 669d21c

Please sign in to comment.