globalize2 is not aware of namespaces
Reported by Kane | May 1st, 2009 @ 01:54 AM
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
No comments found
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
The second incarnation of Globalize for Rails, which will let your Rails app speak any language on Earth, and beyond.