Skip to content
This repository has been archived by the owner on Dec 22, 2018. It is now read-only.

Commit

Permalink
Use I18n.available_locales to build @locales options
Browse files Browse the repository at this point in the history
This is more "the Rails way (tm)" and therefore less magic for new developers, but also comes with a bonus advantage: It's possible to check in new locale files or keep no longer maintained existing ones while excluding them from the language dropdowns.
  • Loading branch information
Sven Schwyn authored and frenkel committed Oct 11, 2018
1 parent 4115152 commit ddf473d
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,8 @@ def load_labels

def set_locale
@time_zones = ActiveSupport::TimeZone.all.map(&:name).sort
@locales = []

Dir.open("#{Rails.root}/config/locales").each do |file|
unless ['.', '..'].include?(file) || file[0] == '.'
code = file[0...-4] # strip of .yml
@locales << [I18n.translate(:language_name, locale: code), code]
end
@locales = I18n.available_locales.map do |locale|
[I18n.translate(:language_name, locale: locale), locale]
end

if user_signed_in? && !current_user.locale.blank?
Expand Down

0 comments on commit ddf473d

Please sign in to comment.