| Path: | README |
| Last Update: | Tue Jan 22 18:12:10 -0500 2008 |
Gibberish Rails 0.1
An extension to Gibberish and Rails to use it to create a multilingual web site using the around filter and Gibberish.
The latest version of gibberish_rails can be found here: svn.myutil.com/projects/plugins/gibberish_rails/
Other info can be found here: myutil.com/2008/1/22/gibberish_rails-a-ruby-on-rails-plugin-to-translate-rails-with-gibberish
This is an alpha release. Tests are not written yet. I expected this plugin to be radically rewritten (simplified?) once Rails core is fixed to allow for localization of messages. The issue for Rails core tracking this is here: dev.rubyonrails.org/ticket/9726. I probably didn‘t find and fix all the messages in validates let alone rails but this should be useful to anyone trying to use Gibberish to run a multi-lingual web site.
This plugin:
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
Notes:
This plugin doesn‘t know anything about your models. In prototyping, I translated restful_authentication login and signup screens and need gibberish to pick up some of my model attribute names and some other miscellaneous strings. So, I hackishly put a file in my models directory that‘s only use is for Peter‘s gibberish_translate plugin to pick up the strings:
-------- models/translate_me.rb------------------
"Password confirmation"[]
"Password"[]
"user"[]
If you are using Peter Marklund‘s gibberish_translate (www.marklunds.com/articles/one/376), the you should change the directories it search to include this one. Also Peter‘s plugin doesn‘t pick up the Gibberish String "foo"[] (which is another way of saying "foo"[:foo]). Redefine Gibberish::Extractor methods in his plugin to be:
def dirs_to_search
%w(app config lib vendor/plugins/gibberish_rails).map { |dir| "#{RAILS_ROOT}/#{dir}" }
end
def message_pattern(start_token, end_token)
/#{start_token}((?:[^#{end_token}](?:\\#{end_token})?)+)#{end_token}\[:*([a-z_]*)[,\]]/m
end
def add_messages(contents, start_token, end_token)
contents.scan(message_pattern(start_token, end_token)).each do |text, key|
key = text.tr('[ ]', '_').downcase if ( key == '' )
add_message(key, remove_quotes(text, end_token))
end
end
Known Issue:
When the fields in a form are translated and validated, the div's that created the red boxes aren't working...have to look into that at some point.
Copyright (c) 2008 MyUtil(tm), released under the MIT license
Portions of code above Copyright (c) 2007 Peter Marklund: svn.marklunds.com/plugins/gibberish_translate/MIT-LICENSE