Skip to content

Commit

Permalink
Merge pull request #127 from sshaw/master
Browse files Browse the repository at this point in the history
Remove incorrect info on setting I18n.locale
  • Loading branch information
namusyaka committed Feb 11, 2017
2 parents 818517d + f0ea423 commit 7ae9d6d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 18 additions & 6 deletions guides/03_features/08_localization.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ zip your files and send it to [padrinorb@gmail.com](mailto:padrinorb@gmail.org)

## How to localize your app

The first thing that you need to do is to set your locale by appending it to
`boot.rb`:
The request's locale can be set in a [route filter](http://padrinorb.com/guides/controllers/route-filters/):

```ruby
Padrino.before_load do
# Route filter
before do
I18n.locale = :de
end
```

Or within a route:

```ruby
get "/" do
I18n.locale = :de
end
```
Expand All @@ -78,6 +86,8 @@ you will get:
=> "Bar"
```

For more ways to configure the locale see [Sinatra's I18n recipe](http://recipes.sinatrarb.com/p/development/i18n).

--------------------------------------------------------------------------------

## Translate Models (ActiveRecord)
Expand Down Expand Up @@ -153,9 +163,10 @@ column names of grids, forms, error_messages etc ...

--------------------------------------------------------------------------------

## Bonus
## Form Builders

Using `form_builder` like:
[Form builder](http://padrinorb.com/guides/application-helpers/form-builders/) labels are
automatically translated:

```haml
-form_for :account, url(:accounts_create, :format => :js), :remote => true do |f|
Expand All @@ -171,4 +182,5 @@ Using `form_builder` like:
%td=f.select :role, :options => access_control.roles
```

the tag **label** automatically translates for **you** the field name!
It looks for translations with a key of `MODEL.attributes.ATTRIBUTE` where `MODEL` is
the name of the model passed to `form_for` and `ATTRIBUTE` is the given attribute name.
4 changes: 4 additions & 0 deletions guides/06_application-helpers/06_form-builders.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ within `form_for` or `fields_for` are:
- `f.image_submit "submit.png", :class => 'long'`

For a complete list checkout [the form helper docs](http://www.rubydoc.info/gems/padrino-helpers/Padrino/Helpers/FormHelpers "Form Helper Docs").

## Localization

See [localization](/guides/features/localization/).

0 comments on commit 7ae9d6d

Please sign in to comment.