Reputation: 26272
Other than copying Facebook's SELECT and OPTION elements, is there a Rails-native way of generating a Facebook-esque, localized-language select list?
Upvotes: 2
Views: 285
Reputation: 159145
If by "Rails-native" you mean "provided by Rails core," then no. However, you can access a list of locales your app provides translations for via I18n.available_locales
. If one of the values of your locale is a localized version of the name of the language, you can use it to build a select:
# as a helper
def available_locales
I18n.available_locales.map{ |l| [t('name', :locale => l), l] }
end
# in a view
= select_tag :language, options_for_select(available_locales, I18n.locale.to_sym)
If you want something that will build the list for you, you might check out a Gem or plugin, such as localized_language_select.
Upvotes: 3