Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation when using with SimpleForm #1160

Open
eric-hemasystems opened this issue Nov 9, 2020 · 1 comment
Open

Translation when using with SimpleForm #1160

eric-hemasystems opened this issue Nov 9, 2020 · 1 comment
Labels
Help Wanted simple_form Specific to simple_form gem

Comments

@eric-hemasystems
Copy link

When using Ransack with SimpleForm the translation is not working. If I do:

<%= f.input :status_eq, collection: %w[Active Inactive] %>

Then my label ends up being "Status eq" rather than "Status equal". This is due to not using the translation support in Ransack. This could be an issue for SimpleForm rather than Ransack. But since the existing integration between the two systems has Ransack modifying itself for SimpleForm rather than the other way around it seemed perhaps start with an issue here.

I do have a monkey-patch to fix it up but it involves monkey-patching a SimpleForm method so not sure it is a suitable strategy. If you don't see another strategy from the Ransack side I can try opening a ticket with SimpleForm to see if they would be willing to modify their method.

My monkey-patch:

module SimpleFormRansackTranslate
  # Adapted from:
  #   https://github.com/activerecord-hackery/ransack/blob/master/lib/ransack/helpers/form_builder.rb#L35-L37
  #
  # Decorating:
  #   https://github.com/heartcombo/simple_form/blob/master/lib/simple_form/components/labels.rb#L75-L83
  #
  # NOTE: Decorated method is protected so higher risk of breakage on upgrade
  def label_translation
    if object.respond_to? :translate
      object.translate reflection_or_attribute_name.to_s, include_associations: true
    else
      super
    end
  end
end

SimpleForm::Inputs::Base.prepend SimpleFormRansackTranslate

This related to PR #341 where support for SimpleForm was added.

@scarroll32 scarroll32 added simple_form Specific to simple_form gem Help Wanted labels Jan 23, 2021
@abinoam
Copy link

abinoam commented Apr 14, 2024

Hi @eric-hemasystems

If you still interested in Ransack / SimpleForm integration I would appreciate your feedback in my PR at #1487

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted simple_form Specific to simple_form gem
Projects
None yet
Development

No branches or pull requests

3 participants