Gibberish Rails plugin

Plugin details

An extension to Gibberish and Rails to use it to create a multilingual web site using the around filter and Gibberish.

Websitehttp://myutil.com/2008/1/22/gibberish_rails-a-ruby-on-rails-plugin-to-translate-rails-with-gibberish Repositoryhttp://svn.myutil.com/projects/plugins/gibberish_rails/ Author Rama McIntosh Tags Gibberish, l10n LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.myutil.com/projects/plugins/gibberish_rails/

1. Adds the method Gibberish.supported? to Gibberish::Localize to use it's map of languages to determine if a locale is supported. For example Gibberish.supported?(:en) returns true. It can be passed a string or a symbol. The previous Gibberish API returned an array of languages, but it was just so much more efficient to use the hash Gibberish had already built I added my method to the api. My Helper (6) below needs this method.

2. Redefines the Rails core method ActionView::Helpers::ActiveRecordHelper.error_message_for so messages are translates with Gibberish.

3. Overrides default error messages in ActiveReccord:Errors to include a Gibberish key. The key is blank (i.e. the entire string) so they can be automatically re-Gibberished in step 4. (next).

4. The method "add" in ActiveRecord::Errors has been overridden retranslate messages during the around filter. This become necessary because Rails 2.0.2 caches parts of messages at the class load time.

5. Redefines the method Validations.ClassMethods.validates_length_of to retranslate the messages it caches at class load up time.

6. Adds a helper method "GibberishRails.best_guess_locale" that can be used in an around filter to determine the "best guess" locale the application should be using. The highest priority is given to a parameter, followed by HTTP_ACCEPT_LANGUAGE, and finally the Gibberish default. Also, if the user wants es-mx and we support es, it will return a local of es. Here is an example usage that uses the session to cache the locale so if you are using the HTTP_ACCEPT_LANGUAGE (instead of RESTful routes), it will cache in the session instead of parsing headers every time:

      class ApplicationController < ActionController::Base
        # ...
        around_filter :use_best_guess_locale
        # ...
        # Set's the best guess language Giberish's around filter
        def use_best_guess_locale
          session[:locale] = GibberishRails.best_guess_locale(params[:locale], request.env['HTTP_ACCEPT_LANGUAGE']) if ( ! session[:locale] || params[:locale] || RAILS_ENV == 'development' )

          Gibberish.use_language(session[:locale]) { 
            yield
          }
        end
      end

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 8 months ago