Multilingual form

I have a problem sending multiple language translations for model data in the same form. For instance:

Publication Model:

translates :title 

How can I post in a β€œnew” view of actions that contains a form so that I can present my title in both: en locale and: fr locale, for example?

Thanks.

+6
source share
1 answer

You can look at https://github.com/alvarezrilla/batch_translations

In Rails 3 and globalize3, I had to change a few things to make it work correctly. Change all globalize_translations methods to just translations, remove the proc.binding parameters in @ template.concat and add to your model

 has_many :translations accepts_nested_attributes_for :translations 

But it all works.

Your form should look something like this:

  <%= form_for(@category) do |f| %> <%= render "shared/error_messages", :target => @category %> <table class="zebra"> <tbody> <%= f.globalize_fields_for(:fr) do |g| %> <tr> <td><%= t(:language).humanize %>: <%= t(:french).humanize %></td> <td></td> </tr> <tr> <td> <%= g.label :name, t(:name).humanize %><br/> <%= g.text_field :name %> </td> </tr> <tr> <td> <%= g.label :description, t(:description).humanize %><br/> <%= g.text_area :description, :rows => 40, :cols => 100, :class => "mceEditor" %> </td> </tr> <% end %> <%= f.globalize_fields_for(:en) do |g| %> <tr> <td><%= t(:language).humanize %>: <%= t(:english).humanize %></td> <td></td> </tr> <tr> <td> <%= g.label :name, t(:name).humanize %><br/> <%= g.text_field :name %> </td> </tr> <tr> <td> <%= g.label :description, t(:description).humanize %><br/> <%= g.text_area :description, :rows => 40, :cols => 100, :class => "mceEditor" %> </td> </tr> <% end %> </tbody> </table> <div class="actions"> <%= f.submit :class=>'button' %> <%= yield :actions %> </div> <% end %> 

If you have more problems, I will run a working version of this for Rails 3.

+5
source

Source: https://habr.com/ru/post/888849/


All Articles