Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

globalize2 is not aware of namespaces

#11

I have namespaced models so i quickly found this lack. i made a quick fix, it is proberbly not the best code but it works for me (for now).

I also changed the behaviour for getting the tablename for the translation table, so it gets the tablename of the klass and appends _translations. so if i set the tablename manually the translationtable is named similary.

in lib/globalize/model/active_record/active_record.rb:

    def create_proxy_class(klass)
      result = klass.name.match(/(.*)::(.*)/)
      if result
        namespace = eval("::#{result[1]}")
        klassname = result[2]
      else
         namespace = Object
         klassname = klass.name
      end
      namespace.const_set "#{klassname}Translation", Class.new(klass.superclass) {
        belongs_to "#{klassname}".intern, :class_name => "#{klass.name}"

        set_table_name "#{klass.table_name}_translations"

and in translated.rb in the ClassMethods module:

      #TODO: hier wude auch gefixt
        translation_table_name = self.table_name + '_translations'
        self.connection.create_table(translation_table_name) do |t|
          result = self.name.match(/(.*)::(.*)/)
          name = result  ? result[2] : self.name
          t.references name.downcase
          t.string :locale
          fields.each do |name, type|
            t.column name, type
          end
          t.timestamps              
        end
      end

      def drop_translation_table!
        #TODO: hier wude auch gefixt
        translation_table_name = self.table_name + '_translations'
        self.connection.drop_table translation_table_name
      end

      private

      def i18n_attr(attribute_name)
        #TODO: hier wude auch gefixt
        self.table_name + "_translations.#{attribute_name}"
      end          
    end

Reported by Kane · May 1st, 2009 @ 01:54 AM

State: new
Milestone: none
Assigned to: nobody

Activity

No comments yet.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.