Skip to content

Instantly share code, notes, and snippets.

@laurynas
Created January 14, 2011 13:33
Show Gist options
  • Save laurynas/779607 to your computer and use it in GitHub Desktop.
Save laurynas/779607 to your computer and use it in GitHub Desktop.
Multi locale field builder
# depends on i18n_multi_locales_form plugin
# rails plugin install https://github.com/ZenCocoon/i18n_multi_locales_form.git
module MultiLocaleFieldBuilder
def multi_locale_field(method, opts = {})
opts = {
:type => :text_field
}.merge(opts)
type = opts.delete(:type)
html = []
I18n.available_locales.each do |locale|
html << self.send(type, method, opts.merge(:locale => locale, :title => locale.to_s.upcase)) + " " + locale.to_s.upcase
end
html.join('<br />').html_safe
end
end
ActionView::Helpers::FormBuilder.send(:include, MultiLocaleFieldBuilder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment