Skip to content

Add controller to input translation #1464

Open
@leonelgalan

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions