https://github.com/crunch09/form_translation
language specific inputs in your forms
https://github.com/crunch09/form_translation
Last synced: over 1 year ago
JSON representation
language specific inputs in your forms
- Host: GitHub
- URL: https://github.com/crunch09/form_translation
- Owner: Crunch09
- License: mit
- Created: 2013-06-28T14:03:45.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2017-01-04T17:21:08.000Z (over 9 years ago)
- Last Synced: 2024-10-18T11:26:41.127Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 1.46 MB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# FormTranslation
[](https://codeclimate.com/github/Crunch09/form_translation)
[](https://travis-ci.org/Crunch09/form_translation)
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:
```ruby
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.
```ruby
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 a `languagify` block.
```erb
<%= simple_form_for(@article) do |f| %>
<%= f.input :date %>
<%= f.languagify do |l| %>
<%= l.input :subject %>
<%= l.input :body %>
<% end %>
<%= f.button :submit %>
<% 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`
```ruby
def article_params
params.require(:article).permit(:subject, :body, :de_subject, :de_body)
end
```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request