Skip to content

Localization Reference

cainlevy edited this page Sep 14, 2010 · 7 revisions

How it Works

ActiveScaffold facilitates localization by using the Object#as_() method:


<h4><%= as_('Are you sure?') -%></h4>

In the config block ActiveScaffold delays localization until after the session is known, so that you have the chance to know what the target locale should be. Assign the value to the config element:


active_scaffold :event do |config|
  config.columns[:address].label = 'Mailing Address'
end

and ActiveScaffold will call the Object#as_() method later.

How to Localize ActiveScaffold

Choose a localization plugin or gem. The Ruby on Rails website maintains a nice .rubyonrails.org/rails/pages/InternationalizationComparison of localization options. The .globalize-rails.org/globalize/ and the .gnu.org/software/gettext/ appear to be the most widely adopted options.

Then override Object#as_() and redirect control to the plugin or gem:


def as_(*args)
  # place custom localization handling here like
  _(*args)
end

Another Option

At one time ActiveScaffold did more than just facilitate localization. When it was decided to remove that code from core, it was captured in the .google.com/p/activescaffoldlocalize/. This plugin localizes all of the ActiveScaffold strings. It also demonstrates a very simple mechanism for localizing your application.

Bonus Localization

ActiveScaffold will also use the DATE_FORMATS[:default] string for dates and times, if present. More information can be found .rubyonrails.org/rails/pages/HowToDefineYourOwnDateFormat.

Clone this wiki locally