Files
grecia/app/components/admin/locales/form_component.rb
Javi Martín 0c59c2dfb4 Extract model to handle locales settings
This way we can simplify the view, particularly the form. However, we're
still adding some complexity to the form so inputs are inside labels and
so the collection is easier to style with CSS.
2024-06-05 16:10:56 +02:00

31 lines
629 B
Ruby

class Admin::Locales::FormComponent < ApplicationComponent
attr_reader :locales_settings
use_helpers :name_for_locale
def initialize(locales_settings)
@locales_settings = locales_settings
end
private
def available_locales
I18n.available_locales
end
def many_available_locales?
available_locales.count > select_field_threshold
end
def locales_options
available_locales.map { |locale| [name_for_locale(locale), locale] }
end
def select_field_threshold
10
end
def attribute_name(...)
locales_settings.class.human_attribute_name(...)
end
end