Adventures with Ruby

Localizing Dates and Times in Rails 2.2

View Comments

Here is the next installment of a series of guides I’m writing for internationalizing a Rails 2.2 application. Please read the first part, Translating ActiveRecord, if you haven’t already. This time I’m going to talk about how to localize dates and times to a specific language.

Read the rest of this entry »

Written by Iain Hecker

October 8th, 2008 at 9:39 pm

Posted in iain.nl

Resources

View Comments

Just a simple little advice for all RESTful programmers out there. It’s really simple, and cleans up your code quite a bit. A lot of Rails applications have two roles: an admin and non admin. Your code can get pretty ugly when implementing extra features for the admin. Read the rest of this entry »

Written by Iain Hecker

September 29th, 2008 at 11:17 pm

Posted in Uncategorized

acts_as_translatable_model plugin

View Comments

After a long day in the train today, I extracted the I18n functionality from ActiveRecord so its applicable to any class. This can be especially handy if the source of the data is different, e.g. LDAP. Just install the plugin and add one line to your class to make it translatable:

[sourcecode language='bash']./script/plugin install git://github.com/iain/acts_as_translatable_model[/sourcecode]

[sourcecode language='ruby']
class User
acts_as_translatable_model

attr_accessor :name, :password
end
[/sourcecode]

Now you can do familiar things with the class, just as you would do with normal ActiveRecord models. Read the rest of this entry »

Written by Iain Hecker

September 22nd, 2008 at 10:54 pm

Posted in Uncategorized

Form Labels in Rails 2.2

View Comments

Shamelessly copy-pasted from the README file of the new plugin I released today:

Since form labels don’t use I18n in Rails 2.2 (I was too late in submitting the patch), we’d have to make due with a plugin.

Installation and configuration consists of 1 easy steps:

  1. Run: ./script/plugin install git://github.com/iain/i18n_label.git

Example

In your translation file:

en-US:
  activerecord:
    attributes:
      topic:
        name: 'A nice name'

In your view:

<% form_for Topic.new do |f| %>
  <%= f.label :name %>
<% end %>

The result is:

<label for="topic_name">A nice name</label>

For more information about where to put your translations, read my post about translating ActiveRecord.

Written by Iain Hecker

September 12th, 2008 at 9:55 pm

Posted in Uncategorized

Plugin: translatable_columns

View Comments

It was just three days ago when I discussed how to translate columns. At the moment I was writing it, I was already thinking: “this should be a plugin”. So today, I took the liberty and created it.

Contents

  1. Installing
  2. Usage
  3. Validating
  4. Customizing
  5. Some extras

Read the rest of this entry »

Written by Iain Hecker

September 6th, 2008 at 8:19 pm

Posted in Uncategorized

Fork me on GitHub