BrainBuster Globalized!

During the last week I created a small patch that allows Brain Buster Logic Capthca plugin to cooperate with Globalize by asking only questions that match the specified language.

To archive this I’ve changed ‘brain_buster.rb’ as follow:

def self.find_random_or_previous(id = nil)

@loc = (Locale.language_code.to_s.blank? ? "en" : Locale.language_code.to_s)

if id.nil?

self.find(random_id(first_id, count(:conditions=>["lang = ?",@loc])),:conditions=>["lang = ?",@loc])

else

find(id,:conditions=>["lang = ?",@loc])

end

end

private

# return first valid id

def self.first_id

if find(:all,:conditions=>["lang = ?",@loc], :o rder => "id").length == 0

@loc = "en"

end

@first_id = find(:all,:conditions=>["lang = ?",@loc], :o rder => "id").first.id

end

and then I created a migration which add a ‘lang’ column to the brain buster table:

class BusterAndLanguage < ActiveRecord::Migration

def self.up

add_column :brain_busters, :lang, :string, :default=>"en"

end

def self.down

remove_column :brain_busters, :lang

end

end

That’s it; now we need just to fill the table with questions and answers for the languages we want to add to our application.

Leave a Comment

*