FormTranslation
It uses ActiveRecord::Store
to store language specific values and adds
tabs to your forms for each language.
Installation
Add this line to your application's Gemfile:
gem 'form_translation', github: 'Crunch09/form_translation'
And then execute:
$ bundle
$ rails g form_translation:install
Usage
- In your model include `FormTranslation::ForModel* and specify which attributes should be translated.
class Article < ActiveRecord::Base
include FormTranslation::ForModel
translate_me :subject, :body
end
- Within your
simple_form
-Form specify where to put your translation-tabs with alanguagify
block.
<%= simple_form_for(@article) do |f| %>
<div class="form-inputs">
<%= f.input :date %>
</div>
<div>
<%= f.languagify do |l| %>
<%= l.input :subject %>
<%= l.input :body %>
<% end %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
Lastly, make sure to add the translated attributes to your permitted parameters
so they can be stored. The convention for the attribute name is as follows:
language_shortname
_attribute_name
def article_params
params.require(:article).permit(:subject, :body, :de_subject, :de_body)
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request