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

Add controller to input translation #1464

Open
leonelgalan opened this issue Feb 20, 2017 · 0 comments
Open

Add controller to input translation #1464

leonelgalan opened this issue Feb 20, 2017 · 0 comments

Comments

@leonelgalan
Copy link

Currently it is possible to customize the translation to be used based on the action. This is done, by asking the builder for its lookup_action, which get's the controller action's name and runs it through a simple mapping to map 'create' => 'new' and 'update' => 'edit' and configuring the locales:

In my case, Notification is a general purpose way of notifying users about different things and has different delivery mechanisms: in-app message, email, push notifications. So my labels, placeholders and hints might differ depending on the controller the form is being rendered. Often the show action of this controllers also includes a @notification to render a form in the footer.

en:
  simple_form:
    hints:
      notification:
        new:
          title: This is the subject of the message sent to the user.

Solutions

I'm proposing two different ways to accomplish this. I would like to hear feedback on the desirability of the feature and the feasibility of the proposed solutions. I'm inclining for B, and might start a PR soon as a proof of concept.

A. Include Controller in the Lookup

en:
  simple_form:
    hints:
      notification:
        # Additions:
        'activities#show':
          title: This is the content of the Push Notification received by the user.
        'photos#show':
          title: This would be the subject of the email received by the user

When rendering activities#show ideally this looks the entire controller/action pair, before falling back to the action or to the defaults:

  • notification.activities#show.title
  • notification.show.title
  • notification.title

B. Pass an option to the form to "namespace" the lookup further:

en:
  simple_form:
    hints:
      notification:
        # Additions:
        email:
          title: This is the content of the Push Notification received by the user.
# Inside photos#show
simple_form_for @notification, lookup: 'email' do |f|
  # ...
end

Ideally this looks for the custom lookup first, before falling back to the action and the defaults:

  • notification.email.title
  • notification.show.title
  • notification.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants