开发者

Rails3 Facebook-esque localized language picklist

Other than copying Facebo开发者_运维技巧ok's SELECT and OPTION elements, is there a Rails-native way of generating a Facebook-esque, localized-language select list?

Rails3 Facebook-esque localized language picklist


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜