module ClassMethods # Declare in ActiveRecord or ActiveResource class with localized attributes # You must include the module "manually" in your own classes (ie. put include HasLocalizedAttributes in your class) # See README for example def has_localized_atributes include InstanceMethods unless included_modules.include?(InstanceMethods) end end module InstanceMethods # Define method missing to intercept calls to non-localized methods (eg. +name+ instead of +name_cz+) def method_missing(method_name, *arguments) language = (defined?(Gibberish) ? Gibberish.current_language.to_s : HasLocalizedAttributes.default_language).sub(/cz/, 'cs') # puts "Trying to send '#{method_name}_#{language}' to #{self}" # uncomment for easy debugging in script/console return self.send(:"#{method_name}_#{language}") if self.respond_to?(:"#{method_name}_#{language}") super end end