Isnor Creative
Isnor Creative Blog
Ruby, Ruby on Rails, Ember, Elm, Phoenix, Elixir, React, Vue

Dec 10, 2008

Translates To French

A quick and dirty plugin for Rails 2.2 English sites that need to provide ActiveRecord translations to French. Highly limited and inflexible, but seems to serve my highly limited and inflexible needs at the moment: a single-user CMS content site managed by an English-speaking person. French translations show on the front end if available, and default to English otherwise.

I based it on this post and plugin:
http://iain.nl/2008/09/actsastranslatable_model-plugin/

Usage:

If the locale is set to ‘fr’ it will look for a column with the suffix ‘_fr’. If there’s content available in that column, it will use it, otherwise it will just show the English.

class MyModel < ActiveRecord::Base
  translates_to_french :title, :content
end

I setup an Admin area controller and in there I have a before_filter that resets the locale back to English.

In the forms I provide a field for both the English and French content items.

script/plugin install git://github.com/gordonbisnor/translates_to_french.git


I am available for Ruby on Rails consulting work – get in touch to learn more.

Gordon B. Isnor

Gordon B. Isnor writes about Ruby on Rails, Ember.js, Elm, Elixir, Phoenix, React, Vue and the web.
If you enjoyed this article, you may be interested in the occasional newsletter.

I am now available for project work. I have availability to build greenfield sites and applications, to maintain and update/upgrade existing applications, team augmentation. I offer website/web application assessment packages that can help with SEO/security/performance/accessibility and best practices. Let’s talk

comments powered by Disqus