Trace:
Differences
This shows you the differences between two versions of the page.
— |
localization_with_globalize [2011/08/24 13:35] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | =====Localization with Globalize===== | ||
+ | |||
+ | |||
+ | |||
+ | ====Installation and configuration==== | ||
+ | Installing Globalize is pretty straightforward. See the documentation online: | ||
+ | |||
+ | |||
+ | |||
+ | [[http://www.globalize-rails.org/wiki/|http://www.globalize-rails.org/wiki/]] | ||
+ | |||
+ | |||
+ | |||
+ | Do not forget to: | ||
+ | |||
+ | *include the following lines at the end of your rails_apps/yourAppName/config/environment.rb file: | ||
+ | <code c> | ||
+ | include Globalize | ||
+ | Locale.set_base_language 'nl-NL' | ||
+ | </code> | ||
+ | |||
+ | |||
+ | (or any other base language if you're not in the Netherlands, of course). | ||
+ | |||
+ | |||
+ | |||
+ | *before any filters, add the following line in your file rails_apps/yourAppName/app/controllers/application.rb: | ||
+ | <code c> | ||
+ | Locale.set("nl-NL") | ||
+ | </code> | ||
+ | |||
+ | |||
+ | I have made it a habit to store my translation strings in ''**app/helpers/translations.rb**'' | ||
+ | |||
+ | |||
+ | ====Using Globalize to output plain string dates==== | ||
+ | Using Globalize is also pretty easy. It just melds in with the various ''**date_select**'' functions already present in Rails. These methods allow you to output select boxes where you can select and edit dates. | ||
+ | |||
+ | |||
+ | |||
+ | Outputting a plain formatted date string, however, is not really documented. Here is how you do it: | ||
+ | |||
+ | |||
+ | |||
+ | <code c> | ||
+ | <p><label for="account_logdate">Laatst ingelogd</label><br/> | ||
+ | <span id="account_logdate"><%= @account.logdate.localize("%d %B %Y") %></p> | ||
+ | </code> | ||
+ | |||
+ | |||
+ | This outputs: | ||
+ | |||
+ | |||
+ | |||
+ | <code c> | ||
+ | Laatst ingelogd | ||
+ | 18 januari 2006 | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
You are here: start » localization_with_globalize