README.md in restfulness-0.2.3 vs README.md in restfulness-0.2.4

- old
+ new

@@ -253,11 +253,35 @@ @project ||= Project.find(request.path[:id]) end end ``` +#### I18n in Resources +Restfulness uses the [http_accept_language](https://github.com/iain/http_accept_language) gem to automatically handle the `Accept-Language` header coming in from a client. After trying to make a match between the available locales, it will automatically set the `I18n.locale`. You can access the http_accept_language parser via the `request.http_accept_language` method. + +For most APIs this should work great, especially for mobile applications where this header is automatically set by the phone. There may however be situations where you need a bit more control. If a user has a preferred language setting for example. + +Resources contain two protected methods that can be overwritten if you need more precise control. This is what they look like in the Restfulness code: + +```ruby +protected + +def locale + request.http_accept_language.compatible_language_from(I18n.available_locales) +end + +def set_locale + I18n.locale = locale +end +``` + +The `Resource#set_locale` method is called before any of the other callbacks are handled. This is important as it allows the locale to be set before returning any translatable error messages. + +Most users will probably just want to override the `Resource#locale` method and provide the appropriate locale for the request. If you are using a User object or similar, double check your authentication process as the default `authorized?` method will be called *after* the locale is prepared. + + ### Requests All resource instances have access to a `Request` object via the `#request` method, much like you'd find in a Rails project. It provides access to the details including in the HTTP request: headers, the request URL, path entries, the query, body and/or parameters. Restfulness takes a slightly different approach to handling paths, queries, and parameters. Rails and Sinatra apps will typically mash everything together into a `params` hash. While this is convenient for most use cases, it makes it much more difficult to separate values from different contexts. The effects of this are most noticable if you've ever used Models Backbone.js or similar Javascript library. By default a Backbone Model will provide attributes without a prefix in the POST body, so to be able to differenciate between query, path and body parameters you need to ignore the extra attributes, or hack a part of your code to re-add a prefix. @@ -563,10 +587,14 @@ * Needs more functional testing. * Support for before and after filters in resources, although I'm slightly aprehensive about this. ## History -### 0.2.3 - pending +### 0.2.4 - February 7, 2014 + + * Added I18n support with the help of the http_accept_language gem. (@samlown) + +### 0.2.3 - February 6, 2014 * Fixing issue where query parameters are set as Hash instead of HashWithIndifferentAccess. * Rewinding the body, incase rails got there first. * Updating the README to describe auto-reloading in Rails projects. * Improved handling of Content-Type header that includes encoding. (@awilliams)