norbauer / has_accent
has_accent
PublicAn i18n plugin for translating attributes of ActiveRecord models--plays nice with Gibberish.
README
HasAccent
HasAccent is an internalization plugin for Ruby on Rails. It allows you to easily store and retrieve translations of any of your AR model's string/text fields in the database.
Requirements
Rails 2.1+ is required for this plugin.
Installation
- Sitting in your Rails app root folder:
./script/plugin install git@github.com:norbauer/has_accent.git - Generate the required migrations with:
./script/generate translatable - Run:
rake db:migrate
Configuration
- Open up
environment.rband create a list of available languages. It's recommended to use the language code instead of the full name:
- The HasAccent's default language is english, this means that HasAccent will treat the actual values stored in the ActiveRecord instance as being in English, but you can override this setting. For example, if you want to make French the default language:
- Add the
has_accentcall on any of your ActiveRecord models for which you wish to enable translations, by default all the string/text attributes will be set as translatable.
- You can also override these default settings:
- Once
has_accenthas been set, anytime you create a new record, HasAccent will create empty translation stubs for each of the languages. You can access these translations by callingtranslationson a record (using the example above):
The Translation model attributes are:
-
content - Stores the actual text translation.
-
translatable_attribute - Stores the name of the attribute that this translation is linked to (Using the example above, either 'name' or 'description')
-
language - Stores the language name or code, depending on how you set them up during the configuration ('en', 'fr', 'es', etc...)
Instructions
- Add a
before_filterin any of your Rails controllers to set the current language, ideally in your ApplicationController:
- HasAccent will give you a set of dynamic methods that you can use in your views to return the correct translation based on
HasAccent.current_languagesetting. Using the example above and assuming all translations have been entered:
Copyright (c) 2008 Norbauer Inc, released under the MIT license<br/> Written by Jose Fernandez and Ryan Norbauer, with support from The Sequoyah Group