Ruby Tea with Sugar Rails

Translation for your Ruby on Rails App



I am writing this article with accompanied by a cup of coffee while waiting MU Vs Chealsea for Champion Final. Back to the topic. You should know many familiar online translation like google and altavista. Now i will like to introduce you about gibberish in rails. Let start it :

  • Install the plugin to your app rails.
ruby script/plugin install http://svn.myutil.com/projects/plugins/gibberish_rails/
or
ruby script/plugin install svn://errtheblog.com/svn/plugins/gibberish
  • After that go to your Application_controller.rb then use arround_filter for implementation of gibberish :
class ApplicationController < ActionController::Base
around_filter :set_language

private
def set_language
Gibberish.use_language(session[:language]) { yield }
end
end
  • Another method is described in README file. Like :
class ApplicationController < ActionController::Base
around_filter :use_best_guess_locale

private
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
  • To create new dictionary, you can create it in YAML file such as es.yaml :
welcome_friend: ¡Recepción, amigo!
welcome_user: ¡Recepción, {user}!
love_rails: Amo los carriles.



_

0 comments: