Home > Mobile >  How to translate the disable_with message
How to translate the disable_with message

Time:07-19

I have this link and I would like to have the disabled_with translated properly.

Unfortunately, this does not work withing the block of {}.

The translated string does not get interpolated and when i press the button, the button changes to "#{i18n.t(:client_wait_message)}".

Is there any other way to make this work?

For example, the <%= t :client_loading_button_message %> right before the <% end %> outputs the translated string just fine. Thank you so much

   <%= link_to "launch_presentation_return_url",
        {
        data: {turbo: false, 
        disable_with: '<i ></i>#{i18n.t(:client_wait_message)}'},
        class: 'btn btn-primary float-right',
        'data-toggle' => 'tooltip',
         'data-placement' => 'top',
         'title' => 'test',
          'data-original-title' => '',
                            } do %>
           <i ></i>
             <%= t :client_loading_button_message %>
             <% end %>

Edited to working solution:

<%= link_to session.to_hash["api_request_params"]["launch_presentation_return_url"],
                       html_options =
                       {
                          data:
                            {
                              turbo: false
                            },
                          'data-disable-with' =>
                          "<i class='fa fa-spinner fa-spin'></i>#{t :client_loading_button_message}",
                          class:  'btn btn-primary float-right',
                          'data-toggle'    => 'tooltip',
                          'data-placement' => 'top',
                          'title'          => "#{t :client_loading_button_message}",
                          'data-original-title' => "",
                        } do %>
                            <i ></i>
                            <%= t :client_loading_button_message %>
                      <% end %>

CodePudding user response:

No, because the string you have the attempted translation in is a single-quoted string: '<i ></i>#{i18n.t(:client_wait_message)}' That won't interpolate the #{}.

Change it to a double-quoted string, and then you'll find out that it's I18n not i18n, although probably just a bare t here will work.

  • Related