Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove incorrect info on setting I18n.locale #127

Merged
merged 1 commit into from Feb 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions guides/03_features/08_localization.html.md
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
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/).