administrate
administrate copied to clipboard
handling translation for select fields
- What were you trying to do?
- Trying to figure out the correct way to handle translations for select fields
- What did you end up with (logs, or, even better, example apps are great!)? in ProgramDashboard
ATTRIBUTE_TYPES = {
publication_status: Field::Select.with_options(
collection: Program.present_publication_status_select
),
}
in program.rb
enum session_subscription_mode: { sliding: 'sliding', unique: 'unique', selectable: 'selectable' }, _prefix: :session_subscription_mode
def self.present_session_subscription_modes_select
Program.session_subscription_modes.map do |k, v|
[
I18n.t(
"activerecord.attributes.program.session_subscription_modes.#{k}"
), v
]
end
end
However for select field it seems like the locale is not reloaded all the time and I don't end up with the right translations. What is the correct way of handling I18n translations for select fields ?
- What versions are you running?
- Rails 6.0.3
- administrate 0.15.0
I'm not sure if this will work, but you can use any sort of call-able as the collection option, for example a lambda. This should allow for more dynamic collections, and might work for locale changes.
ATTRIBUTE_TYPES = {
publication_status: Field::Select.with_options(
collection: ->() { Program.present_publication_status_select }
),
}
Let us know if this works.
Closing due to lack of activity.